xref: /PHP-7.4/ext/phar/tests/phar_setalias2.phpt (revision 26dfce7f)
1--TEST--
2Phar::setAlias() error
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
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===DONE===
39--CLEAN--
40<?php
41unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
42unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
43unlink(__DIR__ . '/notphar.phar');
44__HALT_COMPILER();
45?>
46--EXPECTF--
47hio
48test
49alias "test" is already used for archive "%sphar_setalias2.phar.php" and cannot be used for other archives
50alias "test" is already used for archive "%sphar_setalias2.phar.php" cannot be overloaded with "%snope.phar"
51===DONE===
52