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