xref: /PHP-8.4/ext/phar/tests/zip/refcount1.phpt (revision 74859783)
1--TEST--
2Phar: test that refcounting avoids problems with deleting a file zip-based
3--EXTENSIONS--
4phar
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--CLEAN--
46<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
47--EXPECTF--
48===CLOSE===
49object(PharFileInfo)#%d (2) {
50  [%spathName":%sSplFileInfo":private]=>
51  string(%d) "phar://%srefcount1.phar.zip/b/c.php"
52  [%sfileName":%sSplFileInfo":private]=>
53  string(%d) "c.php"
54}
55string(5) "extra"
56===UNLINK===
57
58Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.zip", has open file pointers, cannot unlink in %srefcount1.php on line %d
59object(PharFileInfo)#%d (2) {
60  [%spathName":%sSplFileInfo":private]=>
61  string(%d) "phar://%srefcount1.phar.zip/b/c.php"
62  [%sfileName":%sSplFileInfo":private]=>
63  string(%s) "c.php"
64}
65string(5) "extra"
66extra
67