xref: /PHP-7.1/ext/phar/tests/metadata_write.phpt (revision e3de409e)
1--TEST--
2Phar with meta-data (write)
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6if (version_compare(PHP_VERSION, "6.0", "==")) die("skip pre-unicode version of PHP required");
7?>
8--INI--
9phar.require_hash=0
10phar.readonly=0
11--FILE--
12<?php
13$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
14$pname = 'phar://' . $fname;
15$file = "<?php __HALT_COMPILER(); ?>";
16
17$files = array();
18$files['a'] = array('cont' => 'a');
19$files['b'] = array('cont' => 'b', 'meta' => 'hi there');
20$files['c'] = array('cont' => 'c', 'meta' => array('hi', 'there'));
21$files['d'] = array('cont' => 'd', 'meta' => array('hi'=>'there','foo'=>'bar'));
22include 'files/phar_test.inc';
23
24foreach($files as $name => $cont) {
25	var_dump(file_get_contents($pname.'/'.$name));
26}
27
28$phar = new Phar($fname);
29$phar['a']->setMetadata(42);
30$phar['b']->setMetadata(NULL);
31$phar['c']->setMetadata(array(25, 'foo'=>'bar'));
32$phar['d']->setMetadata(true);
33
34foreach($files as $name => $cont) {
35	var_dump($phar[$name]->getMetadata());
36}
37
38unset($phar);
39
40foreach($files as $name => $cont) {
41	var_dump(file_get_contents($pname.'/'.$name));
42}
43?>
44===DONE===
45--CLEAN--
46<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
47--EXPECT--
48string(1) "a"
49string(1) "b"
50string(1) "c"
51string(1) "d"
52int(42)
53NULL
54array(2) {
55  [0]=>
56  int(25)
57  ["foo"]=>
58  string(3) "bar"
59}
60bool(true)
61string(1) "a"
62string(1) "b"
63string(1) "c"
64string(1) "d"
65===DONE===
66