dir_basic.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --TEST--
  2. Test dir() function : basic functionality
  3. --FILE--
  4. <?php
  5. echo "*** Testing dir() : basic functionality ***\n";
  6. // include the file.inc for Function: function create_files()
  7. include(__DIR__."/../file/file.inc");
  8. // create the temporary directory
  9. $file_path = __DIR__;
  10. $dir_path = $file_path."/dir_basic";
  11. @mkdir($dir_path);
  12. // create files within the temporary directory
  13. create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "dir_basic");
  14. echo "Get Directory instance:\n";
  15. $d = dir($dir_path);
  16. var_dump( $d );
  17. echo "\nRead and rewind:\n";
  18. var_dump( $d->read() );
  19. var_dump( $d->read() );
  20. var_dump( $d->rewind() );
  21. echo "\nTest using handle directly:\n";
  22. var_dump( readdir($d->handle) );
  23. var_dump( readdir($d->handle) );
  24. echo "\nClose directory:\n";
  25. var_dump( $d->close() );
  26. var_dump( $d );
  27. echo "\nTest read after closing the dir:\n";
  28. try {
  29. var_dump( $d->read() );
  30. } catch (TypeError $e) {
  31. echo $e->getMessage(), "\n";
  32. }
  33. // delete temp files
  34. delete_files($dir_path, 3, "dir_basic", 1, ".tmp");
  35. echo "Done";
  36. ?>
  37. --CLEAN--
  38. <?php
  39. $file_path = __DIR__;
  40. $dir_path = $file_path."/dir_basic";
  41. rmdir($dir_path);
  42. ?>
  43. --EXPECTF--
  44. *** Testing dir() : basic functionality ***
  45. Get Directory instance:
  46. object(Directory)#%d (2) {
  47. ["path"]=>
  48. string(%d) "%s/dir_basic"
  49. ["handle"]=>
  50. resource(%d) of type (stream)
  51. }
  52. Read and rewind:
  53. string(%d) "%s"
  54. string(%d) "%s"
  55. NULL
  56. Test using handle directly:
  57. string(%d) "%s"
  58. string(%d) "%s"
  59. Close directory:
  60. NULL
  61. object(Directory)#%d (2) {
  62. ["path"]=>
  63. string(%d) "%s/dir_basic"
  64. ["handle"]=>
  65. resource(%d) of type (Unknown)
  66. }
  67. Test read after closing the dir:
  68. Directory::read(): supplied resource is not a valid Directory resource
  69. Done