xref: /PHP-7.0/ext/phar/tests/dir.phpt (revision 16b4d8e0)
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 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
11$pname = 'phar://' . $fname;
12$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
13$pname2 = 'phar://' . $fname2;
14$fname3 = dirname(__FILE__) . '/' . 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://' . dirname(__FILE__) . '/ok.phar/fails');
36mkdir('phar://' . dirname(__FILE__) . '/ok.phar/fails');
37file_put_contents('phar://' . dirname(__FILE__) . '/ok.phar/sub/directory.txt', 'hi');
38mkdir('phar://' . dirname(__FILE__) . '/ok.phar/sub');
39mkdir('phar://' . dirname(__FILE__) . '/ok.phar/sub/directory.txt');
40file_put_contents(dirname(__FILE__) . '/oops.phar', '<?php this should screw em up __HALT_COMPILER();');
41mkdir('phar://' . dirname(__FILE__) . '/oops.phar/fails');
42
43mkdir('phar://');
44rmdir('phar://');
45rmdir('phar://' . dirname(__FILE__) . '/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===DONE===
54--CLEAN--
55<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
56<?php unlink(dirname(__FILE__) . '/ok.phar'); ?>
57<?php unlink(dirname(__FILE__) . '/oops.phar'); ?>
58<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php'); ?>
59<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?>
60--EXPECTF--
61bool(true)
62bool(true)
63bool(true)
64bool(true)
65bool(false)
66bool(true)
67bool(false)
68
69Warning: mkdir(): phar error: cannot create directory "phar://%sdir.phar.php/fails", write operations disabled in %sdir.php on line %d
70
71Warning: mkdir(): phar error: cannot create directory "fails" in phar "%sok.phar", directory already exists in %sdir.php on line %d
72
73Warning: mkdir(): phar error: cannot create directory "sub" in phar "%sok.phar", directory already exists in %sdir.php on line %d
74
75Warning: 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
76
77Warning: mkdir(): internal corruption of phar "%soops.phar" (truncated manifest at stub end) in %sdir.php on line %d
78
79Warning: mkdir(): phar error: cannot create directory "phar://", no phar archive specified in %sdir.php on line %d
80
81Warning: rmdir(): phar error: cannot remove directory "phar://", no phar archive specified, or phar archive does not exist in %sdir.php on line %d
82
83Warning: rmdir(): phar error: cannot remove directory "hi" in phar "%sunknown.phar", directory does not exist in %sdir.php on line %d
84
85Warning: rmdir(): phar error: cannot rmdir directory "phar://%sdir.phar.php/another/dir", write operations disabled in %sdir.php on line %d
86
87Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d
88
89Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d
90
91Warning: 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
92===DONE===