xref: /PHP-8.1/ext/phar/tests/phar_decompress.phpt (revision 74859783)
1--TEST--
2Phar::decompress()
3--EXTENSIONS--
4phar
5zlib
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$zip = $phar->convertToData(Phar::ZIP);
36ini_set('phar.readonly', 1);
37try {
38    $gz->decompress();
39} catch (Exception $e) {
40    echo $e->getMessage() . "\n";
41}
42try {
43    $zip->decompress();
44} catch (Exception $e) {
45    echo $e->getMessage() . "\n";
46}
47?>
48--CLEAN--
49<?php
50unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
51unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.zip');
52unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.hooba.phar');
53unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar');
54unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.gz');
55unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar.gz');
56unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar');
57?>
58--EXPECTF--
59int(4096)
60%sphar_decompress2.phar
61%sphar_decompress.phar
62%sphar_decompress.hooba.phar
63Cannot decompress phar archive, phar is read-only
64Cannot decompress zip-based archives with whole-archive compression
65