xref: /PHP-8.3/ext/phar/tests/zip/all.phpt (revision 98d004c9)
1--TEST--
2Phar: test that creation of zip-based phar generates valid zip with all bells/whistles
3--EXTENSIONS--
4phar
5zlib
6bz2
7--INI--
8phar.readonly=0
9--FILE--
10<?php
11
12$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
13$pname = 'phar://' . $fname;
14$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
15$pname2 = 'phar://' . $fname2;
16
17$phar = new Phar($fname);
18
19$phar->setMetadata('hi there');
20$phar['a'] = 'hi';
21$phar['a']->setMetadata('a meta');
22$phar['b'] = 'hi2';
23$phar['b']->compress(Phar::GZ);
24$phar['c'] = 'hi3';
25$phar['c']->compress(Phar::BZ2);
26$phar['b']->chmod(0444);
27$phar->setStub("<?php ok __HALT_COMPILER();");
28$phar->setAlias("hime");
29unset($phar);
30copy($fname, $fname2);
31Phar::unlinkArchive($fname);
32var_dump(file_exists($fname), file_exists($pname . '/a'));
33
34$phar = new Phar($fname2);
35var_dump($phar['a']->getContent(), $phar['b']->getContent(), $phar['c']->getContent());
36var_dump($phar['a']->isCompressed(), $phar['b']->isCompressed() == Phar::GZ, $phar['c']->isCompressed() == Phar::BZ2);
37var_dump((string) decoct(fileperms($pname2 . '/b')));
38var_dump($phar->getStub());
39var_dump($phar->getAlias());
40var_dump($phar->getMetadata());
41var_dump($phar['a']->getMetadata());
42?>
43--CLEAN--
44<?php
45@unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
46unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php');
47?>
48--EXPECT--
49bool(false)
50bool(false)
51string(2) "hi"
52string(3) "hi2"
53string(3) "hi3"
54bool(false)
55bool(true)
56bool(true)
57string(6) "100444"
58string(32) "<?php ok __HALT_COMPILER(); ?>
59"
60string(4) "hime"
61string(8) "hi there"
62string(6) "a meta"
63