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