1--TEST--
2Phar::unlinkArchive()
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.require_hash=0
7phar.readonly=0
8--FILE--
9<?php
10
11try {
12Phar::unlinkArchive("");
13} catch (Exception $e) {
14echo $e->getMessage(),"\n";
15}
16
17$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
18$pdname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
19
20try {
21Phar::unlinkArchive($fname);
22} catch (Exception $e) {
23echo $e->getMessage(),"\n";
24}
25file_put_contents($pdname, 'blahblah');
26try {
27Phar::unlinkArchive($pdname);
28} catch (Exception $e) {
29echo $e->getMessage(),"\n";
30}
31Phar::unlinkArchive(array());
32
33$pname = 'phar://' . $fname;
34$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
35$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
36$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
37$file = $stub;
38
39$files = array();
40$files['a'] = 'a';
41$files['b'] = 'b';
42$files['c'] = 'c';
43
44include 'files/phar_test.inc';
45
46$phar = new Phar($fname);
47var_dump($phar->isFileFormat(Phar::ZIP));
48var_dump($phar->getStub());
49try {
50Phar::unlinkArchive($fname);
51} catch (Exception $e) {
52echo $e->getMessage(),"\n";
53}
54$phar = $phar->convertToExecutable(Phar::ZIP);
55var_dump($phar->isFileFormat(Phar::ZIP));
56var_dump($phar->getStub());
57
58copy($fname2, $fname3);
59
60$phar = new Phar($fname3);
61var_dump($phar->isFileFormat(Phar::ZIP));
62var_dump($phar->getStub());
63
64Phar::unlinkArchive($fname);
65var_dump(file_exists($fname));
66$phar = new Phar($fname);
67var_dump(count($phar));
68$phar['evil.php'] = '<?php
69try {
70Phar::unlinkArchive(Phar::running(false));
71} catch (Exception $e) {echo $e->getMessage(),"\n";}
72var_dump(Phar::running(false));
73include Phar::running(true) . "/another.php";
74?>';
75$phar['another.php'] = "hi\n";
76unset($phar);
77include $pname . '/evil.php';
78?>
79===DONE===
80--CLEAN--
81<?php
82unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
83unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
84unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
85unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
86__HALT_COMPILER();
87?>
88--EXPECTF--
89Unknown phar archive ""
90Unknown phar archive "%sphar_unlinkarchive.phar"
91Unknown phar archive "%sphar_unlinkarchive.phar.tar": internal corruption of phar "%sphar_unlinkarchive.phar.tar" (truncated entry)
92
93Warning: Phar::unlinkArchive() expects parameter 1 to be %string, array given in %sphar_unlinkarchive.php on line %d
94bool(false)
95string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
96phar archive "%sphar_unlinkarchive.phar" has open file handles or objects.  fclose() all file handles, and unset() all objects prior to calling unlinkArchive()
97bool(true)
98string(60) "<?php // zip-based phar archive stub file
99__HALT_COMPILER();"
100bool(true)
101string(60) "<?php // zip-based phar archive stub file
102__HALT_COMPILER();"
103bool(false)
104int(0)
105phar archive "%sphar_unlinkarchive.phar" cannot be unlinked from within itself
106string(%d) "%sphar_unlinkarchive.phar"
107hi
108===DONE===
109