xref: /PHP-8.2/ext/phar/tests/phar_stub.phpt (revision 74859783)
1--TEST--
2Phar::setStub()
3--EXTENSIONS--
4phar
5--INI--
6phar.require_hash=0
7phar.readonly=0
8--FILE--
9<?php
10$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
11$pname = 'phar://' . $fname;
12$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
13
14$files = array();
15$files['a'] = 'a';
16$files['b'] = 'b';
17$files['c'] = 'c';
18
19include 'files/phar_test.inc';
20
21$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
22$fp = fopen($fname, 'rb');
23//// 1
24echo fread($fp, strlen($file)) . "\n";
25fclose($fp);
26$phar = new Phar($fname);
27$file = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
28
29//// 2
30$phar->setStub($file);
31$fp = fopen($fname, 'rb');
32echo fread($fp, strlen($file)) . "\n";
33fclose($fp);
34
35$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.phartmp.php';
36$file = '<?php echo "third stub\n"; __HALT_COMPILER(); ?>';
37$fp = fopen($fname2, 'wb');
38fwrite($fp, $file);
39fclose($fp);
40$fp = fopen($fname2, 'rb');
41
42//// 3
43$phar->setStub($fp);
44fclose($fp);
45
46$fp = fopen($fname, 'rb');
47echo fread($fp, strlen($file)) . "\n";
48fclose($fp);
49
50$fp = fopen($fname2, 'ab');
51fwrite($fp, 'booya');
52fclose($fp);
53echo file_get_contents($fname2) . "\n";
54
55$fp = fopen($fname2, 'rb');
56
57//// 4
58$phar->setStub($fp, strlen($file));
59fclose($fp);
60
61$fp = fopen($fname, 'rb');
62echo fread($fp, strlen($file)) . "\n";
63if (fread($fp, strlen('booya')) == 'booya') {
64    echo 'failed - copied booya';
65}
66fclose($fp);
67$phar['testing'] = 'hi';
68
69// ensure stub is not overwritten
70$fp = fopen($fname, 'rb');
71echo fread($fp, strlen($file)) . "\n";
72if (fread($fp, strlen('booya')) == 'booya') {
73    echo 'failed - copied booya';
74}
75fclose($fp);
76
77?>
78--CLEAN--
79<?php
80unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
81unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
82__HALT_COMPILER();
83?>
84--EXPECT--
85<?php echo "first stub\n"; __HALT_COMPILER(); ?>
86<?php echo "second stub\n"; __HALT_COMPILER(); ?>
87<?php echo "third stub\n"; __HALT_COMPILER(); ?>
88<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
89<?php echo "third stub\n"; __HALT_COMPILER(); ?>
90<?php echo "third stub\n"; __HALT_COMPILER(); ?>
91