xref: /PHP-5.6/ext/phar/tests/fopen_edgecases.phpt (revision 16b4d8e0)
1--TEST--
2Phar: fopen/stat/fseek/unlink/rename edge cases
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.readonly=0
7phar.require_hash=0
8--FILE--
9<?php
10$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
11$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php';
12$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar.php';
13$pname = 'phar://' . $fname;
14$pname2 = 'phar://' . $fname2;
15$pname3 = 'phar://' . $fname3;
16
17// create in cwd
18chdir(dirname(__FILE__));
19file_put_contents('phar://fopen_edgetest.phar/hi', 'hi');
20// append
21$a = fopen($pname . '/b/c.php', 'a');
22// invalid pharname
23$a = fopen($pname . '.phar.gz', 'r');
24// test phar_open_url() with quiet stat for code coverage
25var_dump(file_exists($pname . '.phar.gz/hi'));
26// test open for write with new phar
27$a = fopen($pname . '/hi', 'w');
28fclose($a);
29// test open for write with corrupted phar
30file_put_contents($fname2, '<?php oh crap __HALT_COMPILER();');
31$a = fopen($pname2 . '/hi', 'w');
32$a = fopen('phar://', 'r');
33$a = fopen('phar://foo.phar', 'r');
34
35file_put_contents($pname . '/hi', 'hi');
36$a = fopen($pname . '/hi', 'r');
37var_dump(fseek($a, 1), ftell($a));
38var_dump(fseek($a, 1, SEEK_CUR), ftell($a));
39fclose($a);
40
41var_dump(stat('phar://'));
42var_dump(stat('phar://foo.phar'));
43var_dump(is_dir($pname));
44
45// this tests coverage of the case where the phar exists and has no files
46$phar = new Phar($fname3);
47var_dump(file_exists($pname3 . '/test'));
48
49unlink($pname2 . '/hi');
50unlink('phar://');
51unlink('phar://foo.phar');
52unlink($pname . '/oops');
53
54rename('phar://', 'phar://');
55rename($pname . '/hi', 'phar://');
56rename('phar://foo.phar/hi', 'phar://');
57rename($pname . '/hi', 'phar://foo.phar/hi');
58
59ini_set('phar.readonly', 1);
60rename($pname . '/hi', $pname . '/there');
61ini_set('phar.readonly', 0);
62Phar::unlinkArchive($fname);
63file_put_contents($pname . '/test.php', '<?php
64$a = fopen("./notfound.php", "r");
65?>');
66include $pname . '/test.php';
67?>
68
69===DONE===
70--CLEAN--
71<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
72<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?>
73<?php unlink(dirname(__FILE__) . '/fopen_edgetest.phar');
74--EXPECTF--
75Warning: fopen(phar://%sfopen_edgecases.phar.php/b/c.php): failed to open stream: phar error: open mode append not supported in %sfopen_edgecases.php on line %d
76
77Warning: fopen(phar://%sfopen_edgecases.phar.php.phar.gz): failed to open stream: phar error: invalid url or non-existent phar "phar://%sfopen_edgecases.phar.php.phar.gz" in %sfopen_edgecases.php on line %d
78bool(false)
79
80Warning: fopen(phar://%sfopen_edgecases.2.phar.php/hi): failed to open stream: internal corruption of phar "%sfopen_edgecases.2.phar.php" (truncated manifest at stub end) in %sfopen_edgecases.php on line %d
81
82Warning: fopen(phar://): failed to open stream: phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar) in %sfopen_edgecases.php on line %d
83
84Warning: fopen(phar://foo.phar): failed to open stream: %s in %sfopen_edgecases.php on line %d
85int(0)
86int(1)
87int(0)
88int(2)
89
90Warning: stat(): stat failed for phar:// in %sfopen_edgecases.php on line %d
91bool(false)
92
93Warning: stat(): stat failed for phar://foo.phar in %sfopen_edgecases.php on line %d
94bool(false)
95bool(true)
96bool(false)
97
98Warning: unlink(): internal corruption of phar "%sfopen_edgecases.2.phar.php" (truncated manifest at stub end) in %sfopen_edgecases.php on line %d
99
100Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d
101
102Warning: unlink(): phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar) in %sfopen_edgecases.php on line %d
103
104Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d
105
106Warning: unlink(): phar error: invalid url or non-existent phar "phar://foo.phar" in %sfopen_edgecases.php on line %d
107
108Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d
109
110Warning: unlink(): unlink of "phar://%sfopen_edgecases.phar.php/oops" failed, file does not exist in %sfopen_edgecases.php on line %d
111
112Warning: rename(): phar error: cannot rename "phar://" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d
113
114Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d
115
116Warning: rename(): phar error: cannot rename "phar://foo.phar/hi" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d
117
118Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://foo.phar/hi", not within the same phar archive in %sfopen_edgecases.php on line %d
119
120Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://%sfopen_edgecases.phar.php/there": invalid or non-writable url "phar://%sfopen_edgecases.phar.php/hi" in %sfopen_edgecases.php on line %d
121
122Warning: fopen(./notfound.php): failed to open stream: No such file or directory in phar://%sfopen_edgecases.phar.php/test.php on line %d
123
124===DONE===