xref: /PHP-7.4/ext/phar/tests/zip/all.phpt (revision 26dfce7f)
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===DONE===
46--CLEAN--
47<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
48<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php'); ?>
49--EXPECT--
50bool(false)
51bool(false)
52string(2) "hi"
53string(3) "hi2"
54string(3) "hi3"
55bool(false)
56bool(true)
57bool(true)
58string(6) "100444"
59string(32) "<?php ok __HALT_COMPILER(); ?>
60"
61string(4) "hime"
62string(8) "hi there"
63string(6) "a meta"
64===DONE===
65