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