xref: /PHP-7.2/ext/phar/tests/tar/tar_003.phpt (revision 4f9daeed)
1--TEST--
2Phar: tar-based phar, valid 1
3--SKIPIF--
4<?php if (!extension_loaded('phar')) die('skip'); ?>
5<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
6--INI--
7phar.readonly=0
8phar.require_hash=0
9--FILE--
10<?php
11include dirname(__FILE__) . '/files/tarmaker.php.inc';
12
13$fname = dirname(__FILE__) . '/tar_003.phar.tar';
14$alias = 'phar://' . $fname;
15
16$tar = new tarmaker($fname, 'none');
17$tar->init();
18$tar->addFile('.phar/stub.php', "<?php // tar-based phar archive stub file\n__HALT_COMPILER();");
19$tar->addFile('tar_003.phpt', $g = fopen(__FILE__, 'r'));
20$tar->addFile('internal/file/here', "hi there!\n");
21$tar->mkDir('internal/dir');
22$tar->mkDir('dir');
23$tar->close();
24
25fclose($g);
26
27echo file_get_contents($alias . '/internal/file/here');
28
29try {
30$tar = opendir($alias . '/');
31} catch (Exception $e) {
32echo $e->getMessage()."\n";
33}
34
35while (false !== ($v = readdir($tar))) {
36	echo (is_file($alias . '/' . $v) ? "file\n" : "dir\n");
37	echo $v . "\n";
38}
39closedir($tar);
40
41/* ensure none of the dir tar files were freed */
42echo "second round\n";
43$tar = opendir($alias . '/');
44while (false !== ($v = readdir($tar))) {
45	echo (is_file($alias . '/' . $v) ? "file\n" : "dir\n");
46	echo $v . "\n";
47}
48closedir($tar);
49
50?>
51===DONE===
52--CLEAN--
53<?php
54@unlink(dirname(__FILE__) . '/tar_003.phar.tar');
55?>
56--EXPECT--
57hi there!
58dir
59dir
60dir
61internal
62file
63tar_003.phpt
64second round
65dir
66dir
67dir
68internal
69file
70tar_003.phpt
71===DONE===
72