readdir_variation3.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. Test readdir() function : usage variations - sub-directories
  3. --FILE--
  4. <?php
  5. /*
  6. * Pass a directory handle pointing to a directory that has a sub-directory
  7. * to test behaviour of readdir()
  8. */
  9. echo "*** Testing readdir() : usage variations ***\n";
  10. // include the file.inc for Function: function create_files()
  11. chdir(__DIR__);
  12. include(__DIR__."/../file/file.inc");
  13. $path_top = __DIR__ . '/readdir_variation3';
  14. $path_sub = $path_top . '/sub_folder';
  15. mkdir($path_top);
  16. mkdir($path_sub);
  17. create_files($path_top, 2);
  18. create_files($path_sub, 2);
  19. $dir_handle = opendir($path_top);
  20. while(FALSE !== ($file = readdir($dir_handle))) {
  21. // different OS order files differently so will
  22. // store file names into an array so can use sorted in expected output
  23. $contents[] = $file;
  24. }
  25. // more important to check that all contents are present than order they are returned in
  26. sort($contents);
  27. var_dump($contents);
  28. delete_files($path_top, 2);
  29. delete_files($path_sub, 2);
  30. closedir($dir_handle);
  31. ?>
  32. --CLEAN--
  33. <?php
  34. $path_top = __DIR__ . '/readdir_variation3';
  35. $path_sub = $path_top . '/sub_folder';
  36. rmdir($path_sub);
  37. rmdir($path_top);
  38. ?>
  39. --EXPECT--
  40. *** Testing readdir() : usage variations ***
  41. array(5) {
  42. [0]=>
  43. string(1) "."
  44. [1]=>
  45. string(2) ".."
  46. [2]=>
  47. string(9) "file1.tmp"
  48. [3]=>
  49. string(9) "file2.tmp"
  50. [4]=>
  51. string(10) "sub_folder"
  52. }