xref: /PHP-8.1/ext/phar/tests/phar_stub_error.phpt (revision 74859783)
1--TEST--
2Phar::setStub()/getStub()
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$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
13$file = $stub;
14
15$files = array();
16$files['a'] = 'a';
17
18include 'files/phar_test.inc';
19
20$phar = new Phar($fname);
21var_dump($stub);
22var_dump($phar->getStub());
23var_dump($phar->getStub() == $stub);
24
25$newstub = '<?php echo "second stub\n"; _x_HALT_COMPILER(); ?>';
26try
27{
28    $phar->setStub($newstub);
29}
30catch(exception $e)
31{
32    echo 'Exception: ' . $e->getMessage() . "\n";
33}
34var_dump($phar->getStub());
35var_dump($phar->getStub() == $stub);
36$phar->stopBuffering();
37var_dump($phar->getStub());
38var_dump($phar->getStub() == $stub);
39
40?>
41--CLEAN--
42<?php
43unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
44__HALT_COMPILER();
45?>
46--EXPECTF--
47string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
48string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
49bool(true)
50Exception: illegal stub for phar "%sphar_stub_error.phar.php" (__HALT_COMPILER(); is missing)
51string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
52bool(true)
53string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
54bool(true)
55