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