xref: /PHP-7.2/ext/phar/tests/zip/refcount1.phpt (revision 9c5af4e4)
1--TEST--
2Phar: test that refcounting avoids problems with deleting a file zip-based
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
6--INI--
7phar.readonly=0
8phar.require_hash=0
9--FILE--
10<?php
11
12$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
13$alias = 'phar://' . $fname;
14
15$phar = new Phar($fname);
16$phar->setStub("<?php __HALT_COMPILER(); ?>");
17$phar->setAlias('hio');
18
19$files = array();
20
21$files['a.php'] = '<?php echo "This is a\n"; ?>';
22$files['b.php'] = '<?php echo "This is b\n"; ?>';
23$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
24
25foreach ($files as $n => $file) {
26	$phar[$n] = $file;
27}
28$phar->stopBuffering();
29
30$fp = fopen($alias . '/b/c.php', 'wb');
31fwrite($fp, "extra");
32fclose($fp);
33echo "===CLOSE===\n";
34$b = fopen($alias . '/b/c.php', 'rb');
35$a = $phar['b/c.php'];
36var_dump($a);
37var_dump(fread($b, 20));
38rewind($b);
39echo "===UNLINK===\n";
40unlink($alias . '/b/c.php');
41var_dump($a);
42var_dump(fread($b, 20));
43include $alias . '/b/c.php';
44?>
45
46===DONE===
47--CLEAN--
48<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
49--EXPECTF--
50===CLOSE===
51object(PharFileInfo)#%d (2) {
52  [%spathName":%sSplFileInfo":private]=>
53  string(%d) "phar://%srefcount1.phar.zip/b/c.php"
54  [%sfileName":%sSplFileInfo":private]=>
55  string(%d) "c.php"
56}
57string(5) "extra"
58===UNLINK===
59
60Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.zip", has open file pointers, cannot unlink in %srefcount1.php on line %d
61object(PharFileInfo)#%d (2) {
62  [%spathName":%sSplFileInfo":private]=>
63  string(%d) "phar://%srefcount1.phar.zip/b/c.php"
64  [%sfileName":%sSplFileInfo":private]=>
65  string(%s) "c.php"
66}
67string(5) "extra"
68extra
69===DONE===
70