readdir_variation3.phpt 1.5 KB

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