xref: /PHP-8.2/ext/phar/tests/027.phpt (revision 74859783)
1--TEST--
2Phar: phar:// opendir
3--EXTENSIONS--
4phar
5--INI--
6phar.require_hash=0
7--FILE--
8<?php
9$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
10$pname = 'phar://' . $fname;
11$file = "<?php __HALT_COMPILER(); ?>";
12
13$files = array();
14$files['a.php']   = '<?php echo "This is a\n"; require \''.$pname.'/b.php\'; ?>';
15$files['b.php']   = '<?php echo "This is b\n"; require \''.$pname.'/b/c.php\'; ?>';
16$files['b/c.php'] = '<?php echo "This is b/c\n"; require \''.$pname.'/b/d.php\'; ?>';
17$files['b/d.php'] = '<?php echo "This is b/d\n"; require \''.$pname.'/e.php\'; ?>';
18$files['e.php']   = '<?php echo "This is e\n"; ?>';
19
20include 'files/phar_test.inc';
21
22function dump($phar, $base)
23{
24    var_dump(str_replace(__DIR__, '*', $phar) . $base);
25    $dir = opendir($phar . $base);
26    if ($base == '/')
27    {
28        $base = '';
29    }
30    while (false !== ($entry = readdir($dir))) {
31        $entry = $base . '/' . $entry;
32        var_dump($entry);
33        var_dump(is_dir($phar . $entry));
34        if (is_dir($phar . $entry))
35        {
36            dump($phar, $entry);
37        }
38    }
39}
40
41dump($pname, '/');
42
43$a = opendir($pname);
44// this may stop working in future versions, but is here for code coverage purposes
45echo "fseek on dir handle\n";
46var_dump(fseek($a, 0, SEEK_END), ftell($a));
47var_dump(fseek($a, -1), ftell($a));
48var_dump(fseek($a, 1), ftell($a));
49echo "fwrite on dir handle\n";
50var_dump(fwrite($a, 'hi'));
51var_dump(fstat($a));
52closedir($a);
53echo "opendir edge cases\n";
54var_dump(opendir("phar://"));
55var_dump(opendir("phar://foo.phar/hi"));
56?>
57--CLEAN--
58<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
59--EXPECTF--
60string(%d) "phar://*/027.phar.php/"
61string(6) "/a.php"
62bool(false)
63string(2) "/b"
64bool(true)
65string(%d) "phar://*/027.phar.php/b"
66string(8) "/b/c.php"
67bool(false)
68string(8) "/b/d.php"
69bool(false)
70string(6) "/b.php"
71bool(false)
72string(6) "/e.php"
73bool(false)
74fseek on dir handle
75int(0)
76int(4)
77int(-1)
78int(4)
79int(0)
80int(1)
81fwrite on dir handle
82bool(false)
83bool(false)
84opendir edge cases
85
86Warning: opendir(phar://): Failed to open directory: phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar)
87phar url "phar://" is unknown in %s027.php on line %d
88bool(false)
89
90Warning: opendir(phar://foo.phar/hi): Failed to open directory: phar error: invalid url or non-existent phar "phar://foo.phar/hi"
91phar url "phar://foo.phar/hi" is unknown in %s027.php on line %d
92bool(false)
93