xref: /PHP-7.4/ext/phar/tests/mounteddir.phpt (revision 15b394cc)
1--TEST--
2Phar: mounted manifest directory test
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6?>
7--CONFLICTS--
8tempmanifest1.phar.php
9--INI--
10phar.readonly=0
11--FILE--
12<?php
13$fname = __DIR__ . '/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(__DIR__ . '/testit');
37mkdir(__DIR__ . '/testit/directory');
38file_put_contents(__DIR__ . '/testit/extfile.php', '<?php
39var_dump(__FILE__);
40?>');
41file_put_contents(__DIR__ . '/testit/extfile2.php', '<?php
42var_dump(__FILE__);
43?>');
44include __DIR__ . '/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', __DIR__ . '/this/does/not/exist');
71} catch (Exception $e) {
72echo $e->getMessage(), "\n";
73}
74try {
75Phar::mount($pname . '/testit', __DIR__);
76} catch (Exception $e) {
77echo $e->getMessage(), "\n";
78}
79try {
80Phar::mount($pname . '/testit/extfile.php', __DIR__);
81} catch (Exception $e) {
82echo $e->getMessage(), "\n";
83}
84?>
85===DONE===
86--CLEAN--
87<?php
88@unlink(__DIR__ . '/tempmanifest1.phar.php');
89@unlink(__DIR__ . '/testit/extfile.php');
90@unlink(__DIR__ . '/testit/extfile2.php');
91@rmdir(__DIR__ . '/testit/directory');
92@rmdir(__DIR__ . '/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