readdir_variation4.phpt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. --TEST--
  2. Test readdir() function : usage variations - different file names
  3. --FILE--
  4. <?php
  5. /* Prototype : string readdir([resource $dir_handle])
  6. * Description: Read directory entry from dir_handle
  7. * Source code: ext/standard/dir.c
  8. */
  9. /*
  10. * Pass a directory handle pointing to a directory that contains
  11. * files with different file names to test how readdir() reads them
  12. */
  13. echo "*** Testing readdir() : usage variations ***\n";
  14. $dir_path = dirname(__FILE__) . "/readdir_variation4/";
  15. mkdir($dir_path);
  16. // heredoc string
  17. $heredoc = <<<EOT
  18. hd_file
  19. EOT;
  20. $inputs = array(
  21. // int data
  22. /*1*/ 0,
  23. 1,
  24. 12345,
  25. -2345,
  26. // float data
  27. /*5*/ 10.5,
  28. -10.5,
  29. 12.3456789000e10,
  30. 12.3456789000E-10,
  31. .5,
  32. // empty data
  33. /*10*/ "",
  34. array(),
  35. // string data
  36. /*12*/ "double_file",
  37. 'single_file',
  38. $heredoc,
  39. );
  40. $iterator = 1;
  41. foreach($inputs as $key => $input) {
  42. echo "\n-- Iteration $iterator --\n";
  43. $handle = "fp{$iterator}";
  44. var_dump( $$handle = fopen(@"$dir_path$input.tmp", 'w') );
  45. var_dump( fwrite($$handle, $key));
  46. fclose($$handle);
  47. $iterator++;
  48. };
  49. echo "\n-- Call to readdir() --\n";
  50. $dir_handle = opendir($dir_path);
  51. while(FALSE !== ($file = readdir($dir_handle))){
  52. // different OS order files differently so will
  53. // store file names into an array so can use sorted in expected output
  54. $contents[] = $file;
  55. // remove files while going through directory
  56. @unlink($dir_path . $file);
  57. }
  58. // more important to check that all contents are present than order they are returned in
  59. sort($contents);
  60. var_dump($contents);
  61. closedir($dir_handle);
  62. ?>
  63. ===DONE===
  64. --CLEAN--
  65. <?php
  66. $dir_path = dirname(__FILE__) . "/readdir_variation4/";
  67. rmdir($dir_path);
  68. ?>
  69. --EXPECTF--
  70. *** Testing readdir() : usage variations ***
  71. -- Iteration 1 --
  72. resource(%d) of type (stream)
  73. int(1)
  74. -- Iteration 2 --
  75. resource(%d) of type (stream)
  76. int(1)
  77. -- Iteration 3 --
  78. resource(%d) of type (stream)
  79. int(1)
  80. -- Iteration 4 --
  81. resource(%d) of type (stream)
  82. int(1)
  83. -- Iteration 5 --
  84. resource(%d) of type (stream)
  85. int(1)
  86. -- Iteration 6 --
  87. resource(%d) of type (stream)
  88. int(1)
  89. -- Iteration 7 --
  90. resource(%d) of type (stream)
  91. int(1)
  92. -- Iteration 8 --
  93. resource(%d) of type (stream)
  94. int(1)
  95. -- Iteration 9 --
  96. resource(%d) of type (stream)
  97. int(1)
  98. -- Iteration 10 --
  99. resource(%d) of type (stream)
  100. int(1)
  101. -- Iteration 11 --
  102. resource(%d) of type (stream)
  103. int(2)
  104. -- Iteration 12 --
  105. resource(%d) of type (stream)
  106. int(2)
  107. -- Iteration 13 --
  108. resource(%d) of type (stream)
  109. int(2)
  110. -- Iteration 14 --
  111. resource(%d) of type (stream)
  112. int(2)
  113. -- Call to readdir() --
  114. array(16) {
  115. [0]=>
  116. string(9) "-10.5.tmp"
  117. [1]=>
  118. string(9) "-2345.tmp"
  119. [2]=>
  120. string(1) "."
  121. [3]=>
  122. string(2) ".."
  123. [4]=>
  124. string(4) ".tmp"
  125. [5]=>
  126. string(7) "0.5.tmp"
  127. [6]=>
  128. string(5) "0.tmp"
  129. [7]=>
  130. string(17) "1.23456789E-9.tmp"
  131. [8]=>
  132. string(5) "1.tmp"
  133. [9]=>
  134. string(8) "10.5.tmp"
  135. [10]=>
  136. string(9) "12345.tmp"
  137. [11]=>
  138. string(16) "123456789000.tmp"
  139. [12]=>
  140. string(9) "Array.tmp"
  141. [13]=>
  142. string(15) "double_file.tmp"
  143. [14]=>
  144. string(11) "hd_file.tmp"
  145. [15]=>
  146. string(15) "single_file.tmp"
  147. }
  148. ===DONE===