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