xref: /PHP-5.3/ext/phar/tests/phar_ctx_001.phpt (revision 66908185)
1--TEST--
2Phar context
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 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
12$pname = 'phar://' . $fname;
13$file = '<?php __HALT_COMPILER(); ?>';
14
15$files = array();
16$files['a'] = 'a';
17$files['b'] = 'b';
18$files['c'] = 'c';
19
20include 'files/phar_test.inc';
21
22$phar = new Phar($fname);
23
24var_dump(file_get_contents($pname . '/a'));
25var_dump($phar['a']->isCompressed());
26var_dump(file_get_contents($pname . '/b'));
27var_dump($phar['b']->isCompressed());
28var_dump(file_get_contents($pname . '/c'));
29var_dump($phar['c']->isCompressed());
30
31$context = stream_context_create(array('phar'=> array('compress'=>Phar::GZ, 'metadata' => array(2, b'hi' => 3))));
32$context2 = stream_context_create(array('phar' => array('metadata' => array(4))));
33
34file_put_contents($pname . '/a', b'new a', 0); // no compression
35file_put_contents($pname . '/b', b'new b', 0, $context);
36file_put_contents($pname . '/d', b'new d', 0, $context2);
37
38$phar = new Phar($fname);
39var_dump(file_get_contents($pname . '/a'));
40var_dump($phar['a']->isCompressed());
41var_dump($phar['a']->getMetaData());
42var_dump(file_get_contents($pname . '/b'));
43var_dump($phar['b']->isCompressed());
44var_dump($phar['b']->getMetaData());
45var_dump(file_get_contents($pname . '/c'));
46var_dump($phar['c']->isCompressed());
47var_dump($phar['c']->getMetaData());
48var_dump(file_get_contents($pname . '/d'));
49var_dump($phar['d']->isCompressed());
50var_dump($phar['d']->getMetaData());
51$context2 = stream_context_create(array('phar' => array('metadata' => array(4))));
52$fp = fopen($pname . '/b', 'r+', 0, $context2);
53fclose($fp);
54?>
55==AFTER==
56<?php
57var_dump(file_get_contents($pname . '/b'));
58var_dump($phar['b']->isCompressed());
59var_dump($phar['b']->getMetaData());
60?>
61===DONE===
62--CLEAN--
63<?php
64unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
65?>
66--EXPECT--
67string(1) "a"
68bool(false)
69string(1) "b"
70bool(false)
71string(1) "c"
72bool(false)
73string(5) "new a"
74bool(false)
75NULL
76string(5) "new b"
77bool(true)
78array(2) {
79  [0]=>
80  int(2)
81  ["hi"]=>
82  int(3)
83}
84string(1) "c"
85bool(false)
86NULL
87string(5) "new d"
88bool(false)
89array(1) {
90  [0]=>
91  int(4)
92}
93==AFTER==
94string(5) "new b"
95bool(true)
96array(1) {
97  [0]=>
98  int(4)
99}
100===DONE===