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