xref: /PHP-7.3/ext/phar/tests/zip/getalias.phpt (revision 782352c5)
1--TEST--
2Phar: getAlias() with an existing phar.zip
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9
10$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
11
12// sanity check with a virgin phar.zip
13$phar = new Phar($fname);
14var_dump($phar->getAlias());
15unset($phar);
16
17copy(dirname(__FILE__) . '/files/metadata.phar.zip', $fname);
18
19// existing phar.zip, no alias set
20$phar = new Phar($fname);
21var_dump($phar->getAlias());
22
23// check that default alias can be overwritten
24$phar->setAlias('jiminycricket');
25var_dump($phar->getAlias());
26unset($phar);
27
28// existing phar.zip, alias set
29$phar = new Phar($fname);
30var_dump($phar->getAlias());
31
32// check that alias can't be set manually
33try {
34    $phar['.phar/alias.txt'] = 'pinocchio';
35} catch (Exception $e) {
36    echo $e->getMessage()."\n";
37}
38var_dump($phar->getAlias());
39
40// check that user-defined alias can be overwritten
41$phar->setAlias('pinocchio');
42var_dump($phar->getAlias());
43
44?>
45===DONE===
46--CLEAN--
47<?php
48unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
49__HALT_COMPILER();
50?>
51--EXPECTF--
52string(%d) "%sgetalias.phar.zip"
53string(%d) "%sgetalias.phar.zip"
54string(13) "jiminycricket"
55string(13) "jiminycricket"
56Cannot set alias ".phar/alias.txt" directly in phar "%sgetalias.phar.zip", use setAlias
57string(13) "jiminycricket"
58string(9) "pinocchio"
59===DONE===
60