xref: /PHP-8.0/ext/phar/tests/stat.phpt (revision a555cc0b)
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--CLEAN--
72<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
73--EXPECTF--
74bool(false)
75stat
76array(26) {
77  [0]=>
78  int(12)
79  [1]=>
80  int(%d)
81  [2]=>
82  int(33206)
83  [3]=>
84  int(1)
85  [4]=>
86  int(0)
87  [5]=>
88  int(0)
89  [6]=>
90  int(%s)
91  [7]=>
92  int(2)
93  [8]=>
94  int(%d)
95  [9]=>
96  int(%d)
97  [10]=>
98  int(%d)
99  [11]=>
100  int(%s)
101  [12]=>
102  int(%s)
103  ["dev"]=>
104  int(12)
105  ["ino"]=>
106  int(%d)
107  ["mode"]=>
108  int(33206)
109  ["nlink"]=>
110  int(1)
111  ["uid"]=>
112  int(0)
113  ["gid"]=>
114  int(0)
115  ["rdev"]=>
116  int(%s)
117  ["size"]=>
118  int(2)
119  ["atime"]=>
120  int(%d)
121  ["mtime"]=>
122  int(%d)
123  ["ctime"]=>
124  int(%d)
125  ["blksize"]=>
126  int(%s)
127  ["blocks"]=>
128  int(%s)
129}
130lstat
131array(26) {
132  [0]=>
133  int(12)
134  [1]=>
135  int(%d)
136  [2]=>
137  int(33206)
138  [3]=>
139  int(1)
140  [4]=>
141  int(0)
142  [5]=>
143  int(0)
144  [6]=>
145  int(%s)
146  [7]=>
147  int(2)
148  [8]=>
149  int(%d)
150  [9]=>
151  int(%d)
152  [10]=>
153  int(%d)
154  [11]=>
155  int(%s)
156  [12]=>
157  int(%s)
158  ["dev"]=>
159  int(12)
160  ["ino"]=>
161  int(%d)
162  ["mode"]=>
163  int(33206)
164  ["nlink"]=>
165  int(1)
166  ["uid"]=>
167  int(0)
168  ["gid"]=>
169  int(0)
170  ["rdev"]=>
171  int(%s)
172  ["size"]=>
173  int(2)
174  ["atime"]=>
175  int(%d)
176  ["mtime"]=>
177  int(%d)
178  ["ctime"]=>
179  int(%d)
180  ["blksize"]=>
181  int(%s)
182  ["blocks"]=>
183  int(%s)
184}
185fileperms
186int(33206)
187fileinode
188int(%d)
189filesize
190int(2)
191fileowner
192int(0)
193filegroup
194int(0)
195filemtime
196int(%d)
197fileatime
198int(%d)
199filectime
200int(%d)
201filetype
202string(4) "file"
203is_writable
204bool(true)
205is_writeable
206bool(false)
207is_readable
208bool(true)
209is_executable
210bool(false)
211file_exists
212bool(true)
213is_dir
214bool(false)
215is_file
216bool(true)
217is_link
218bool(false)
219not found
220bool(false)
221not found 2
222
223Warning: fileperms(): stat failed for not/found in phar://%sstat.phar.php/my/index.php on line %d
224bool(false)
225