1--TEST--
2Phar: PharFileInfo compression-related methods
3--EXTENSIONS--
4phar
5zlib
6bz2
7--INI--
8phar.readonly=0
9--FILE--
10<?php
11$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';
12$pname = 'phar://' . $fname;
13
14$phar = new Phar($fname);
15
16$phar['a/b'] = 'hi there';
17
18$b = $phar['a/b'];
19
20try {
21$b->isCompressed(25);
22} catch (Exception $e) {
23echo $e->getMessage() . "\n";
24}
25try {
26$b->compress(25);
27} catch (Exception $e) {
28echo $e->getMessage() . "\n";
29}
30$tar = $phar->convertToData(Phar::TAR);
31
32$c = $tar['a/b'];
33try {
34$c->compress(Phar::GZ);
35} catch (Exception $e) {
36echo $e->getMessage() . "\n";
37}
38try {
39$phar['a']->compress(Phar::GZ);
40} catch (Exception $e) {
41echo $e->getMessage() . "\n";
42}
43ini_set('phar.readonly', 1);
44try {
45$b->compress(Phar::GZ);
46} catch (Exception $e) {
47echo $e->getMessage() . "\n";
48}
49ini_set('phar.readonly', 0);
50var_dump($b->compress(Phar::GZ));
51var_dump($b->compress(Phar::GZ));
52var_dump($b->compress(Phar::BZ2));
53var_dump($b->compress(Phar::BZ2));
54
55echo "decompress\n";
56
57ini_set('phar.readonly', 1);
58try {
59$phar['a/b']->decompress();
60} catch (Exception $e) {
61echo $e->getMessage() . "\n";
62}
63ini_set('phar.readonly', 0);
64try {
65$phar['a']->decompress();
66} catch (Exception $e) {
67echo $e->getMessage() . "\n";
68}
69var_dump($b->decompress());
70var_dump($b->decompress());
71
72?>
73--CLEAN--
74<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
75<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
76--EXPECT--
77Unknown compression type specified
78Unknown compression type specified
79Cannot compress with Gzip compression, not possible with tar-based phar archives
80Phar entry is a directory, cannot set compression
81Phar is readonly, cannot change compression
82bool(true)
83bool(true)
84bool(true)
85bool(true)
86decompress
87Phar is readonly, cannot decompress
88Phar entry is a directory, cannot set compression
89bool(true)
90bool(true)
91