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