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