xref: /PHP-8.2/ext/phar/tests/phar_setalias2.phpt (revision 98d004c9)
1--TEST--
2Phar::setAlias() error
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$phar = new Phar($fname);
22echo $phar->getAlias() . "\n";
23$phar->setAlias('test');
24echo $phar->getAlias() . "\n";
25$b = $phar;
26$phar = new Phar(__DIR__ . '/notphar.phar');
27try {
28    $phar->setAlias('test');
29} catch (Exception $e) {
30    echo $e->getMessage() . "\n";
31}
32try {
33    $b = new Phar(__DIR__ . '/nope.phar', 0, 'test');
34} catch (Exception $e) {
35    echo $e->getMessage() . "\n";
36}
37?>
38--CLEAN--
39<?php
40unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
41?>
42--EXPECTF--
43hio
44test
45alias "test" is already used for archive "%sphar_setalias2.phar.php" and cannot be used for other archives
46alias "test" is already used for archive "%sphar_setalias2.phar.php" cannot be overloaded with "%snope.phar"
47