xref: /PHP-7.2/ext/phar/tests/zip/all.phpt (revision 442fd2f9)
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("spl")) die("skip SPL not available");
7if (!extension_loaded("zlib")) die("skip zlib not available");
8if (!extension_loaded("bz2")) die("skip bz2 not available");
9?>
10--INI--
11phar.readonly=0
12--FILE--
13<?php
14
15$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
16$pname = 'phar://' . $fname;
17$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
18$pname2 = 'phar://' . $fname2;
19
20$phar = new Phar($fname);
21
22$phar->setMetadata('hi there');
23$phar['a'] = 'hi';
24$phar['a']->setMetadata('a meta');
25$phar['b'] = 'hi2';
26$phar['b']->compress(Phar::GZ);
27$phar['c'] = 'hi3';
28$phar['c']->compress(Phar::BZ2);
29$phar['b']->chmod(0444);
30$phar->setStub("<?php ok __HALT_COMPILER();");
31$phar->setAlias("hime");
32unset($phar);
33copy($fname, $fname2);
34Phar::unlinkArchive($fname);
35var_dump(file_exists($fname), file_exists($pname . '/a'));
36
37$phar = new Phar($fname2);
38var_dump($phar['a']->getContent(), $phar['b']->getContent(), $phar['c']->getContent());
39var_dump($phar['a']->isCompressed(), $phar['b']->isCompressed() == Phar::GZ, $phar['c']->isCompressed() == Phar::BZ2);
40var_dump((string) decoct(fileperms($pname2 . '/b')));
41var_dump($phar->getStub());
42var_dump($phar->getAlias());
43var_dump($phar->getMetadata());
44var_dump($phar['a']->getMetadata());
45?>
46===DONE===
47--CLEAN--
48<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
49<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php'); ?>
50--EXPECT--
51bool(false)
52bool(false)
53string(2) "hi"
54string(3) "hi2"
55string(3) "hi3"
56bool(false)
57bool(true)
58bool(true)
59string(6) "100444"
60string(32) "<?php ok __HALT_COMPILER(); ?>
61"
62string(4) "hime"
63string(8) "hi there"
64string(6) "a meta"
65===DONE===
66