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