xref: /PHP-5.3/ext/phar/tests/mounteddir.phpt (revision 228c2886)
1--TEST--
2Phar: mounted manifest directory test
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.readonly=0
10detect_unicode=0
11--FILE--
12<?php
13$fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
14$pname = 'phar://' . $fname;
15
16$a = new Phar($fname);
17$a['index.php'] = '<?php
18Phar::mount("testit", dirname(Phar::running(0)) . "/testit");
19echo file_get_contents(Phar::running(1) . "/testit/extfile.php"), "\n";
20echo file_get_contents(Phar::running(1) . "/testit/directory"), "\n";
21echo file_get_contents(Phar::running(1) . "/testit/existing.txt"), "\n";
22include "testit/extfile.php";
23include "testit/extfile2.php";
24try {
25Phar::mount(".phar/stub.php", dirname(Phar::running(0)) . "/testit/extfile.php");
26} catch (Exception $e) {
27echo $e->getMessage(),"\n";
28}
29?>';
30$a['testit/existing.txt'] = 'oops';
31$a->setStub('<?php
32set_include_path("phar://" . __FILE__);
33include "index.php";
34__HALT_COMPILER();');
35unset($a);
36mkdir(dirname(__FILE__) . '/testit');
37mkdir(dirname(__FILE__) . '/testit/directory');
38file_put_contents(dirname(__FILE__) . '/testit/extfile.php', '<?php
39var_dump(__FILE__);
40?>');
41file_put_contents(dirname(__FILE__) . '/testit/extfile2.php', '<?php
42var_dump(__FILE__);
43?>');
44include dirname(__FILE__) . '/testit/extfile.php';
45include $fname;
46
47$a = opendir($pname . '/testit');
48$out = array();
49while (false !== ($b = readdir($a))) {
50	$out[] = $b;
51}
52sort($out);
53foreach ($out as $b) {
54	echo "$b\n";
55}
56$out = array();
57foreach (new Phar($pname . '/testit') as $b) {
58	$out[] = $b->getPathName();
59}
60sort($out);
61foreach ($out as $b) {
62	echo "$b\n";
63}
64try {
65Phar::mount($pname . '/testit', 'another\\..\\mistake');
66} catch (Exception $e) {
67echo $e->getMessage(), "\n";
68}
69try {
70Phar::mount($pname . '/notfound', dirname(__FILE__) . '/this/does/not/exist');
71} catch (Exception $e) {
72echo $e->getMessage(), "\n";
73}
74try {
75Phar::mount($pname . '/testit', dirname(__FILE__));
76} catch (Exception $e) {
77echo $e->getMessage(), "\n";
78}
79try {
80Phar::mount($pname . '/testit/extfile.php', dirname(__FILE__));
81} catch (Exception $e) {
82echo $e->getMessage(), "\n";
83}
84?>
85===DONE===
86--CLEAN--
87<?php
88@unlink(dirname(__FILE__) . '/tempmanifest1.phar.php');
89@unlink(dirname(__FILE__) . '/testit/extfile.php');
90@unlink(dirname(__FILE__) . '/testit/extfile2.php');
91@rmdir(dirname(__FILE__) . '/testit/directory');
92@rmdir(dirname(__FILE__) . '/testit');
93
94?>
95--EXPECTF--
96string(%d) "%sextfile.php"
97<?php
98var_dump(__FILE__);
99?>
100
101Warning: file_get_contents(phar://%stempmanifest1.phar.php/testit/directory): failed to open stream: phar error: path "testit/directory" is a directory in phar://%stempmanifest1.phar.php/index.php on line %d
102
103oops
104string(%d) "phar://%sextfile.php"
105string(%d) "phar://%sextfile2.php"
106Mounting of .phar/stub.php to %sextfile.php within phar %stests/tempmanifest1.phar.php failed
107.
108..
109directory
110extfile.php
111extfile2.php
112phar://%stempmanifest1.phar.php/testit%cdirectory
113phar://%stempmanifest1.phar.php/testit%cextfile.php
114phar://%stempmanifest1.phar.php/testit%cextfile2.php
115Mounting of /testit to another\..\mistake within phar %stempmanifest1.phar.php failed
116Mounting of /notfound to %stests/this/does/not/exist within phar %stempmanifest1.phar.php failed
117Mounting of /testit to %stests within phar %stests/tempmanifest1.phar.php failed
118Mounting of /testit/extfile.php to %stests within phar %stests/tempmanifest1.phar.php failed
119===DONE===
120