xref: /PHP-7.4/ext/phar/tests/stat.phpt (revision 26dfce7f)
1--TEST--
2Phar: test stat function interceptions
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip");?>
5--INI--
6phar.require_hash=1
7phar.readonly=0
8--FILE--
9<?php
10umask(0);
11Phar::interceptFileFuncs();
12var_dump(stat(""));
13
14$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
15$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.tar';
16$fname3 = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.tar';
17$a = new Phar($fname);
18$a['my/index.php'] = '<?php
19echo "stat\n";
20var_dump(stat("dir/file1.txt"));
21echo "lstat\n";
22var_dump(lstat("dir/file1.txt"));
23echo "fileperms\n";
24var_dump(fileperms("dir/file1.txt"));
25echo "fileinode\n";
26var_dump(fileinode("dir/file1.txt"));
27echo "filesize\n";
28var_dump(filesize("dir/file1.txt"));
29echo "fileowner\n";
30var_dump(fileowner("dir/file1.txt"));
31echo "filegroup\n";
32var_dump(filegroup("dir/file1.txt"));
33echo "filemtime\n";
34var_dump(filemtime("dir/file1.txt"));
35echo "fileatime\n";
36var_dump(fileatime("dir/file1.txt"));
37echo "filectime\n";
38var_dump(filectime("dir/file1.txt"));
39echo "filetype\n";
40var_dump(filetype("dir/file1.txt"));
41echo "is_writable\n";
42var_dump(is_writable("dir/file1.txt"));
43echo "is_writeable\n";
44var_dump(is_writeable("dir/file1.txt"));
45echo "is_readable\n";
46var_dump(is_readable("dir/file1.txt"));
47echo "is_executable\n";
48var_dump(is_executable("dir/file1.txt"));
49echo "file_exists\n";
50var_dump(file_exists("dir/file1.txt"));
51echo "is_dir\n";
52var_dump(is_dir("dir/file1.txt"));
53echo "is_file\n";
54var_dump(is_file("dir/file1.txt"));
55echo "is_link\n";
56var_dump(is_link("dir/file1.txt"));
57echo "not found\n";
58var_dump(file_exists("not/found"));
59echo "not found 2\n";
60var_dump(fileperms("not/found"));
61?>';
62$a['dir/file1.txt'] = 'hi';
63$a['dir/file2.txt'] = 'hi2';
64$a['dir/file3.txt'] = 'hi3';
65$a->setStub('<?php
66set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
67include "my/index.php";
68__HALT_COMPILER();');
69include $fname;
70?>
71===DONE===
72--CLEAN--
73<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
74--EXPECTF--
75bool(false)
76stat
77array(26) {
78  [0]=>
79  int(12)
80  [1]=>
81  int(%d)
82  [2]=>
83  int(33206)
84  [3]=>
85  int(1)
86  [4]=>
87  int(0)
88  [5]=>
89  int(0)
90  [6]=>
91  int(%s)
92  [7]=>
93  int(2)
94  [8]=>
95  int(%d)
96  [9]=>
97  int(%d)
98  [10]=>
99  int(%d)
100  [11]=>
101  int(%s)
102  [12]=>
103  int(%s)
104  ["dev"]=>
105  int(12)
106  ["ino"]=>
107  int(%d)
108  ["mode"]=>
109  int(33206)
110  ["nlink"]=>
111  int(1)
112  ["uid"]=>
113  int(0)
114  ["gid"]=>
115  int(0)
116  ["rdev"]=>
117  int(%s)
118  ["size"]=>
119  int(2)
120  ["atime"]=>
121  int(%d)
122  ["mtime"]=>
123  int(%d)
124  ["ctime"]=>
125  int(%d)
126  ["blksize"]=>
127  int(%s)
128  ["blocks"]=>
129  int(%s)
130}
131lstat
132array(26) {
133  [0]=>
134  int(12)
135  [1]=>
136  int(%d)
137  [2]=>
138  int(33206)
139  [3]=>
140  int(1)
141  [4]=>
142  int(0)
143  [5]=>
144  int(0)
145  [6]=>
146  int(%s)
147  [7]=>
148  int(2)
149  [8]=>
150  int(%d)
151  [9]=>
152  int(%d)
153  [10]=>
154  int(%d)
155  [11]=>
156  int(%s)
157  [12]=>
158  int(%s)
159  ["dev"]=>
160  int(12)
161  ["ino"]=>
162  int(%d)
163  ["mode"]=>
164  int(33206)
165  ["nlink"]=>
166  int(1)
167  ["uid"]=>
168  int(0)
169  ["gid"]=>
170  int(0)
171  ["rdev"]=>
172  int(%s)
173  ["size"]=>
174  int(2)
175  ["atime"]=>
176  int(%d)
177  ["mtime"]=>
178  int(%d)
179  ["ctime"]=>
180  int(%d)
181  ["blksize"]=>
182  int(%s)
183  ["blocks"]=>
184  int(%s)
185}
186fileperms
187int(33206)
188fileinode
189int(%d)
190filesize
191int(2)
192fileowner
193int(0)
194filegroup
195int(0)
196filemtime
197int(%d)
198fileatime
199int(%d)
200filectime
201int(%d)
202filetype
203string(4) "file"
204is_writable
205bool(true)
206is_writeable
207bool(false)
208is_readable
209bool(true)
210is_executable
211bool(false)
212file_exists
213bool(true)
214is_dir
215bool(false)
216is_file
217bool(true)
218is_link
219bool(false)
220not found
221bool(false)
222not found 2
223
224Warning: fileperms(): stat failed for not/found in phar://%sstat.phar.php/my/index.php on line %d
225bool(false)
226===DONE===
227