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