xref: /PHP-5.6/ext/phar/tests/zip/refcount1_5_2.phpt (revision 610c7fbe)
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.2 or earlier"); ?>
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, "extra");
33fclose($fp);
34
35echo "===CLOSE===\n";
36
37$b = fopen($alias . '/b/c.php', 'rb');
38$a = $phar['b/c.php'];
39var_dump($a);
40var_dump(fread($b, 20));
41rewind($b);
42echo "===UNLINK===\n";
43unlink($alias . '/b/c.php');
44var_dump($a);
45var_dump(fread($b, 20));
46include $alias . '/b/c.php';
47?>
48
49===DONE===
50--CLEAN--
51<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
52--EXPECTF--
53===CLOSE===
54object(PharFileInfo)#%d (0) {
55}
56string(5) "extra"
57===UNLINK===
58
59Warning: unlink(): phar error: "b/c.php" in phar "%sefcount1_5_2.phar.zip", has open file pointers, cannot unlink in %sefcount1_5_2.php on line %d
60object(PharFileInfo)#%d (0) {
61}
62string(5) "extra"
63extra
64===DONE===
65