xref: /PHP-8.4/ext/phar/tests/zip/phar_stub.phpt (revision 840d6655)
1--TEST--
2Phar::setStub() (zip-based)
3--EXTENSIONS--
4phar
5--INI--
6phar.require_hash=0
7phar.readonly=0
8--FILE--
9<?php
10$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
11$fname = __DIR__ . '/' . 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 = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
26
27//// 2
28$phar->setStub($file);
29echo $phar->getStub();
30
31$fname3 = __DIR__ . '/' . basename(__FILE__, '.php') . '.phartmp.php';
32$file = '<?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, '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--CLEAN--
61<?php
62unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
63unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php');
64unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
65__HALT_COMPILER();
66?>
67--EXPECTF--
68<?php echo "first stub\n"; __HALT_COMPILER(); ?>
69<?php echo "second stub\n"; __HALT_COMPILER(); ?>
70
71Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
72<?php echo "third stub\n"; __HALT_COMPILER(); ?>
73<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
74
75Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
76<?php echo "third stub\n"; __HALT_COMPILER(); ?>
77<?php echo "third stub\n"; __HALT_COMPILER(); ?>
78