xref: /PHP-8.1/ext/phar/tests/phar_ctx_001.phpt (revision 74859783)
1--TEST--
2Phar context
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$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, 'hi' => 3))));
32$context2 = stream_context_create(array('phar' => array('metadata' => array(4))));
33
34file_put_contents($pname . '/a', 'new a', 0); // no compression
35file_put_contents($pname . '/b', 'new b', 0, $context);
36file_put_contents($pname . '/d', '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--CLEAN--
62<?php
63unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
64?>
65--EXPECT--
66string(1) "a"
67bool(false)
68string(1) "b"
69bool(false)
70string(1) "c"
71bool(false)
72string(5) "new a"
73bool(false)
74NULL
75string(5) "new b"
76bool(true)
77array(2) {
78  [0]=>
79  int(2)
80  ["hi"]=>
81  int(3)
82}
83string(1) "c"
84bool(false)
85NULL
86string(5) "new d"
87bool(false)
88array(1) {
89  [0]=>
90  int(4)
91}
92==AFTER==
93string(5) "new b"
94bool(true)
95array(1) {
96  [0]=>
97  int(4)
98}
99