xref: /PHP-7.4/ext/phar/tests/phar_decompress.phpt (revision 26dfce7f)
1--TEST--
2Phar::decompress()
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
6--INI--
7phar.require_hash=0
8phar.readonly=0
9--FILE--
10<?php
11$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
12$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '2.phar.gz';
13$pname = 'phar://' . $fname;
14$file = '<?php __HALT_COMPILER(); ?>';
15
16$files = array();
17$files['a'] = 'a';
18$files['b'] = 'b';
19$files['c'] = 'c';
20
21include 'files/phar_test.inc';
22
23$phar = new Phar($fname);
24
25$gz = $phar->compress(Phar::GZ);
26copy($gz->getPath(), $fname2);
27$a = new Phar($fname2);
28var_dump($a->isCompressed());
29$unc = $a->compress(Phar::NONE);
30echo $unc->getPath() . "\n";
31$unc2 = $gz->decompress();
32echo $unc2->getPath() . "\n";
33$unc3 = $gz->decompress('hooba.phar');
34echo $unc3->getPath() . "\n";
35$gz->decompress(array());
36$zip = $phar->convertToData(Phar::ZIP);
37ini_set('phar.readonly', 1);
38try {
39$gz->decompress();
40} catch (Exception $e) {
41echo $e->getMessage() . "\n";
42}
43try {
44$zip->decompress();
45} catch (Exception $e) {
46echo $e->getMessage() . "\n";
47}
48?>
49===DONE===
50--CLEAN--
51<?php
52unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
53unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.zip');
54unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.hooba.phar');
55unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar');
56unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.gz');
57unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar.gz');
58unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar');
59?>
60--EXPECTF--
61int(4096)
62%sphar_decompress2.phar
63%sphar_decompress.phar
64%sphar_decompress.hooba.phar
65
66Warning: Phar::decompress() expects parameter 1 to be %string, array given in %sphar_decompress.php on line %d
67Cannot decompress phar archive, phar is read-only
68Cannot decompress zip-based archives with whole-archive compression
69===DONE===
70