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