xref: /PHP-8.0/ext/phar/tests/dir.phpt (revision a555cc0b)
1--TEST--
2Phar: mkdir/rmdir test
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.readonly=0
7phar.require_hash=0
8--FILE--
9<?php
10$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
11$pname = 'phar://' . $fname;
12$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.1.phar.php';
13$pname2 = 'phar://' . $fname2;
14$fname3 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.php';
15$pname3 = 'phar://' . $fname3;
16$phar = new Phar($fname);
17var_dump($phar->isFileFormat(Phar::PHAR));
18
19$phar->addEmptyDir('test');
20var_dump($phar['test']->isDir());
21var_dump($phar['test/']->isDir());
22copy($fname, $fname2);
23mkdir($pname . '/another/dir/');
24var_dump($phar['another/dir']->isDir());
25rmdir($pname . '/another/dir/');
26copy($fname, $fname3);
27clearstatcache();
28var_dump(file_exists($pname . '/another/dir/'));
29var_dump(file_exists($pname2 . '/test/'));
30var_dump(file_exists($pname3 . '/another/dir/'));
31ini_set('phar.readonly', 1);
32mkdir($pname . '/fails');
33ini_set('phar.readonly', 0);
34// create new phar by mkdir
35mkdir('phar://' . __DIR__ . '/ok.phar/fails');
36mkdir('phar://' . __DIR__ . '/ok.phar/fails');
37file_put_contents('phar://' . __DIR__ . '/ok.phar/sub/directory.txt', 'hi');
38mkdir('phar://' . __DIR__ . '/ok.phar/sub');
39mkdir('phar://' . __DIR__ . '/ok.phar/sub/directory.txt');
40file_put_contents(__DIR__ . '/oops.phar', '<?php this should screw em up __HALT_COMPILER();');
41mkdir('phar://' . __DIR__ . '/oops.phar/fails');
42
43mkdir('phar://');
44rmdir('phar://');
45rmdir('phar://' . __DIR__ . '/unknown.phar/hi');
46ini_set('phar.readonly', 1);
47rmdir($pname . '/another/dir');
48ini_set('phar.readonly', 0);
49rmdir($pname);
50rmdir($pname . '/');
51mkdir($pname . '/');
52?>
53--CLEAN--
54<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
55<?php unlink(__DIR__ . '/ok.phar'); ?>
56<?php unlink(__DIR__ . '/oops.phar'); ?>
57<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php'); ?>
58<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?>
59--EXPECTF--
60bool(true)
61bool(true)
62bool(true)
63bool(true)
64bool(false)
65bool(true)
66bool(false)
67
68Warning: mkdir(): phar error: cannot create directory "phar://%sdir.phar.php/fails", write operations disabled in %sdir.php on line %d
69
70Warning: mkdir(): phar error: cannot create directory "fails" in phar "%sok.phar", directory already exists in %sdir.php on line %d
71
72Warning: mkdir(): phar error: cannot create directory "sub" in phar "%sok.phar", directory already exists in %sdir.php on line %d
73
74Warning: mkdir(): phar error: cannot create directory "sub/directory.txt" in phar "%sok.phar", phar error: path "sub/directory.txt" exists and is a not a directory in %sdir.php on line %d
75
76Warning: mkdir(): internal corruption of phar "%soops.phar" (truncated manifest at stub end) in %sdir.php on line %d
77
78Warning: mkdir(): phar error: cannot create directory "phar://", no phar archive specified in %sdir.php on line %d
79
80Warning: rmdir(): phar error: cannot remove directory "phar://", no phar archive specified, or phar archive does not exist in %sdir.php on line %d
81
82Warning: rmdir(): phar error: cannot remove directory "hi" in phar "%sunknown.phar", directory does not exist in %sdir.php on line %d
83
84Warning: rmdir(): phar error: cannot rmdir directory "phar://%sdir.phar.php/another/dir", write operations disabled in %sdir.php on line %d
85
86Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d
87
88Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d
89
90Warning: mkdir(): phar error: cannot create directory "" in phar "%sdir.phar.php", phar error: invalid path "" must not be empty in %sdir.php on line %d
91