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