xref: /PHP-8.3/ext/phar/tests/zip/getalias.phpt (revision 74859783)
1--TEST--
2Phar: getAlias() with an existing phar.zip
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7phar.require_hash=0
8--FILE--
9<?php
10
11$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip';
12
13// sanity check with a virgin phar.zip
14$phar = new Phar($fname);
15var_dump($phar->getAlias());
16unset($phar);
17
18copy(__DIR__ . '/files/metadata.phar.zip', $fname);
19
20// existing phar.zip, no alias set
21$phar = new Phar($fname);
22var_dump($phar->getAlias());
23
24// check that default alias can be overwritten
25$phar->setAlias('jiminycricket');
26var_dump($phar->getAlias());
27unset($phar);
28
29// existing phar.zip, alias set
30$phar = new Phar($fname);
31var_dump($phar->getAlias());
32
33// check that alias can't be set manually
34try {
35    $phar['.phar/alias.txt'] = 'pinocchio';
36} catch (Exception $e) {
37    echo $e->getMessage()."\n";
38}
39var_dump($phar->getAlias());
40
41// check that user-defined alias can be overwritten
42$phar->setAlias('pinocchio');
43var_dump($phar->getAlias());
44
45?>
46--CLEAN--
47<?php
48unlink(__DIR__ . '/' . 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