readdir_variation4.phpt 2.9 KB

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