xref: /PHP-7.0/ext/phar/tests/zip/phar_stub.phpt (revision 883b992e)
1--TEST--
2Phar::setStub() (zip-based)
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.require_hash=0
7phar.readonly=0
8--FILE--
9<?php
10$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
11$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
12$pname = 'phar://' . $fname;
13$pname2 = 'phar://' . $fname2;
14
15$p = new Phar($pname2);
16$p->setStub('<?php echo "first stub\n"; __HALT_COMPILER(); ?>');
17$p['a'] = 'a';
18$p['b'] = 'b';
19$p['c'] = 'c';
20copy($fname2, $fname);
21
22$phar = new Phar($fname);
23echo $phar->getStub();
24
25$file = b'<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
26
27//// 2
28$phar->setStub($file);
29echo $phar->getStub();
30
31$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php';
32$file = b'<?php echo "third stub\n"; __HALT_COMPILER(); ?>';
33$fp = fopen($fname3, 'wb');
34fwrite($fp, $file);
35fclose($fp);
36$fp = fopen($fname3, 'rb');
37
38//// 3
39$phar->setStub($fp);
40fclose($fp);
41
42echo $phar->getStub();
43
44$fp = fopen($fname3, 'ab');
45fwrite($fp, b'booya');
46fclose($fp);
47echo file_get_contents($fname3) . "\n";
48
49$fp = fopen($fname3, 'rb');
50
51//// 4
52$phar->setStub($fp, strlen($file));
53fclose($fp);
54echo $phar->getStub();
55
56$phar['testing'] = 'hi';
57
58echo $phar->getStub();
59?>
60===DONE===
61--CLEAN--
62<?php
63unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
64unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php');
65unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
66__HALT_COMPILER();
67?>
68--EXPECT--
69<?php echo "first stub\n"; __HALT_COMPILER(); ?>
70<?php echo "second stub\n"; __HALT_COMPILER(); ?>
71<?php echo "third stub\n"; __HALT_COMPILER(); ?>
72<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
73<?php echo "third stub\n"; __HALT_COMPILER(); ?>
74<?php echo "third stub\n"; __HALT_COMPILER(); ?>
75===DONE===
76