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