1--TEST--
2Phar: PharFileInfo compression-related methods
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("zlib")) die("skip no zlib"); ?>
6<?php if (!extension_loaded("bz2")) die("skip no bz2"); ?>
7--INI--
8phar.readonly=0
9--FILE--
10<?php
11$fname = dirname(__FILE__) . '/' . 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
20$b->isCompressed(array());
21try {
22$b->isCompressed(25);
23} catch (Exception $e) {
24echo $e->getMessage() . "\n";
25}
26try {
27$b->compress(25);
28} catch (Exception $e) {
29echo $e->getMessage() . "\n";
30}
31$tar = $phar->convertToData(Phar::TAR);
32
33$c = $tar['a/b'];
34try {
35$c->compress(Phar::GZ);
36} catch (Exception $e) {
37echo $e->getMessage() . "\n";
38}
39try {
40$phar['a']->compress(Phar::GZ);
41} catch (Exception $e) {
42echo $e->getMessage() . "\n";
43}
44ini_set('phar.readonly', 1);
45try {
46$b->compress(Phar::GZ);
47} catch (Exception $e) {
48echo $e->getMessage() . "\n";
49}
50ini_set('phar.readonly', 0);
51var_dump($b->compress(Phar::GZ));
52var_dump($b->compress(Phar::GZ));
53var_dump($b->compress(Phar::BZ2));
54var_dump($b->compress(Phar::BZ2));
55
56echo "decompress\n";
57
58ini_set('phar.readonly', 1);
59try {
60$phar['a/b']->decompress();
61} catch (Exception $e) {
62echo $e->getMessage() . "\n";
63}
64ini_set('phar.readonly', 0);
65try {
66$phar['a']->decompress();
67} catch (Exception $e) {
68echo $e->getMessage() . "\n";
69}
70var_dump($b->decompress());
71var_dump($b->decompress());
72
73?>
74===DONE===
75--CLEAN--
76<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
77<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
78--EXPECTF--
79Warning: PharFileInfo::isCompressed() expects parameter 1 to be int, array given in %spharfileinfo_compression.php on line 11
80Unknown compression type specified
81Unknown compression type specified
82Cannot compress with Gzip compression, not possible with tar-based phar archives
83Phar entry is a directory, cannot set compression
84Phar is readonly, cannot change compression
85bool(true)
86bool(true)
87bool(true)
88bool(true)
89decompress
90Phar is readonly, cannot decompress
91Phar entry is a directory, cannot set compression
92bool(true)
93bool(true)
94===DONE===
95