dir_basic.phpt 1.8 KB

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