xref: /PHP-8.0/ext/phar/tests/zip/all.phpt (revision a555cc0b)
1--TEST--
2Phar: test that creation of zip-based phar generates valid zip with all bells/whistles
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6if (!extension_loaded("zlib")) die("skip zlib not available");
7if (!extension_loaded("bz2")) die("skip bz2 not available");
8?>
9--INI--
10phar.readonly=0
11--FILE--
12<?php
13
14$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
15$pname = 'phar://' . $fname;
16$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
17$pname2 = 'phar://' . $fname2;
18
19$phar = new Phar($fname);
20
21$phar->setMetadata('hi there');
22$phar['a'] = 'hi';
23$phar['a']->setMetadata('a meta');
24$phar['b'] = 'hi2';
25$phar['b']->compress(Phar::GZ);
26$phar['c'] = 'hi3';
27$phar['c']->compress(Phar::BZ2);
28$phar['b']->chmod(0444);
29$phar->setStub("<?php ok __HALT_COMPILER();");
30$phar->setAlias("hime");
31unset($phar);
32copy($fname, $fname2);
33Phar::unlinkArchive($fname);
34var_dump(file_exists($fname), file_exists($pname . '/a'));
35
36$phar = new Phar($fname2);
37var_dump($phar['a']->getContent(), $phar['b']->getContent(), $phar['c']->getContent());
38var_dump($phar['a']->isCompressed(), $phar['b']->isCompressed() == Phar::GZ, $phar['c']->isCompressed() == Phar::BZ2);
39var_dump((string) decoct(fileperms($pname2 . '/b')));
40var_dump($phar->getStub());
41var_dump($phar->getAlias());
42var_dump($phar->getMetadata());
43var_dump($phar['a']->getMetadata());
44?>
45--CLEAN--
46<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
47<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php'); ?>
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