1--TEST--
2Test lstat() & stat() functions: basic functionality
3--SKIPIF--
4<?php
5if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6if (substr(PHP_OS, 0, 3) == 'WIN') {
7    die('skip not for Windows');
8}
9?>
10--FILE--
11<?php
12$file_path = __DIR__;
13require("$file_path/file.inc");
14
15echo "*** Testing lstat() & stat() : basic functionality ***\n";
16
17/* creating temp directory and file */
18
19// creating dir
20$dirname = "$file_path/lstat_stat_basic";
21@rmdir($dirname);
22mkdir($dirname);
23// stat of the dir created
24$dir_stat = stat($dirname);
25clearstatcache();
26sleep(2);
27
28// creating file
29$filename = "$dirname/lstat_stat_basic.tmp";
30$file_handle = fopen($filename, "w");
31fclose($file_handle);
32// stat of the file created
33$file_stat = stat($filename);
34sleep(2);
35
36// now new stat of the dir after file is created
37$new_dir_stat = stat($dirname);
38clearstatcache();
39
40// create soft link and record stat
41$sym_linkname = "$file_path/lstat_stat_basic_link.tmp";
42symlink($filename, $sym_linkname);
43// stat of the link created
44$link_stat = lstat($sym_linkname);
45sleep(2);
46// new stat of the file, after a softlink to this file is created
47$new_file_stat = stat($filename);
48clearstatcache();
49
50// stat contains 13 different values stored twice, can be accessed using
51// numeric and named keys, compare them to see they are same
52echo "*** Testing stat() and lstat() : validating the values stored in stat ***\n";
53// Initial stat values
54var_dump( compare_self_stat($file_stat) ); //expect true
55var_dump( compare_self_stat($dir_stat) );  //expect true
56var_dump( compare_self_stat($link_stat) ); // expect true
57
58// New stat values taken after creation of file & link
59var_dump( compare_self_stat($new_file_stat) ); //expect true
60var_dump( compare_self_stat($new_dir_stat) );  // expect true
61
62// compare the two stat values, initial stat and stat recorded after
63// creating files and link, also dump the value of stats
64echo "*** Testing stat() and lstat() : comparing stats (recorded before and after file/link creation) ***\n";
65echo "-- comparing difference in dir stats before and after creating file in it --\n";
66$affected_elements = array( 9, 10, 'mtime', 'ctime' );
67var_dump( compare_stats($dir_stat, $new_dir_stat, $affected_elements, '!=', true) ); // expect true
68
69echo "-- comparing difference in file stats before and after creating link to it --\n";
70var_dump( compare_stats($file_stat, $new_file_stat, $all_stat_keys, "==", true) ); // expect true
71
72echo "Done\n";
73?>
74--CLEAN--
75<?php
76$file_path = __DIR__;
77unlink("$file_path/lstat_stat_basic_link.tmp");
78unlink("$file_path/lstat_stat_basic/lstat_stat_basic.tmp");
79rmdir("$file_path/lstat_stat_basic");
80?>
81--EXPECTF--
82*** Testing lstat() & stat() : basic functionality ***
83*** Testing stat() and lstat() : validating the values stored in stat ***
84bool(true)
85bool(true)
86bool(true)
87bool(true)
88bool(true)
89*** Testing stat() and lstat() : comparing stats (recorded before and after file/link creation) ***
90-- comparing difference in dir stats before and after creating file in it --
91array(26) {
92  [0]=>
93  int(%i)
94  [1]=>
95  int(%i)
96  [2]=>
97  int(%i)
98  [3]=>
99  int(%i)
100  [4]=>
101  int(%i)
102  [5]=>
103  int(%i)
104  [6]=>
105  int(%i)
106  [7]=>
107  int(%i)
108  [8]=>
109  int(%i)
110  [9]=>
111  int(%i)
112  [10]=>
113  int(%i)
114  [11]=>
115  int(%i)
116  [12]=>
117  int(%i)
118  ["dev"]=>
119  int(%i)
120  ["ino"]=>
121  int(%i)
122  ["mode"]=>
123  int(%i)
124  ["nlink"]=>
125  int(%i)
126  ["uid"]=>
127  int(%i)
128  ["gid"]=>
129  int(%i)
130  ["rdev"]=>
131  int(%i)
132  ["size"]=>
133  int(%i)
134  ["atime"]=>
135  int(%i)
136  ["mtime"]=>
137  int(%i)
138  ["ctime"]=>
139  int(%i)
140  ["blksize"]=>
141  int(%i)
142  ["blocks"]=>
143  int(%i)
144}
145array(26) {
146  [0]=>
147  int(%i)
148  [1]=>
149  int(%i)
150  [2]=>
151  int(%i)
152  [3]=>
153  int(%i)
154  [4]=>
155  int(%i)
156  [5]=>
157  int(%i)
158  [6]=>
159  int(%i)
160  [7]=>
161  int(%i)
162  [8]=>
163  int(%i)
164  [9]=>
165  int(%i)
166  [10]=>
167  int(%i)
168  [11]=>
169  int(%i)
170  [12]=>
171  int(%i)
172  ["dev"]=>
173  int(%i)
174  ["ino"]=>
175  int(%i)
176  ["mode"]=>
177  int(%i)
178  ["nlink"]=>
179  int(%i)
180  ["uid"]=>
181  int(%i)
182  ["gid"]=>
183  int(%i)
184  ["rdev"]=>
185  int(%i)
186  ["size"]=>
187  int(%i)
188  ["atime"]=>
189  int(%i)
190  ["mtime"]=>
191  int(%i)
192  ["ctime"]=>
193  int(%i)
194  ["blksize"]=>
195  int(%i)
196  ["blocks"]=>
197  int(%i)
198}
199bool(true)
200-- comparing difference in file stats before and after creating link to it --
201array(26) {
202  [0]=>
203  int(%i)
204  [1]=>
205  int(%i)
206  [2]=>
207  int(%i)
208  [3]=>
209  int(%i)
210  [4]=>
211  int(%i)
212  [5]=>
213  int(%i)
214  [6]=>
215  int(%i)
216  [7]=>
217  int(%i)
218  [8]=>
219  int(%i)
220  [9]=>
221  int(%i)
222  [10]=>
223  int(%i)
224  [11]=>
225  int(%i)
226  [12]=>
227  int(%i)
228  ["dev"]=>
229  int(%i)
230  ["ino"]=>
231  int(%i)
232  ["mode"]=>
233  int(%i)
234  ["nlink"]=>
235  int(%i)
236  ["uid"]=>
237  int(%i)
238  ["gid"]=>
239  int(%i)
240  ["rdev"]=>
241  int(%i)
242  ["size"]=>
243  int(%i)
244  ["atime"]=>
245  int(%i)
246  ["mtime"]=>
247  int(%i)
248  ["ctime"]=>
249  int(%i)
250  ["blksize"]=>
251  int(%i)
252  ["blocks"]=>
253  int(%i)
254}
255array(26) {
256  [0]=>
257  int(%i)
258  [1]=>
259  int(%i)
260  [2]=>
261  int(%i)
262  [3]=>
263  int(%i)
264  [4]=>
265  int(%i)
266  [5]=>
267  int(%i)
268  [6]=>
269  int(%i)
270  [7]=>
271  int(%i)
272  [8]=>
273  int(%i)
274  [9]=>
275  int(%i)
276  [10]=>
277  int(%i)
278  [11]=>
279  int(%i)
280  [12]=>
281  int(%i)
282  ["dev"]=>
283  int(%i)
284  ["ino"]=>
285  int(%i)
286  ["mode"]=>
287  int(%i)
288  ["nlink"]=>
289  int(%i)
290  ["uid"]=>
291  int(%i)
292  ["gid"]=>
293  int(%i)
294  ["rdev"]=>
295  int(%i)
296  ["size"]=>
297  int(%i)
298  ["atime"]=>
299  int(%i)
300  ["mtime"]=>
301  int(%i)
302  ["ctime"]=>
303  int(%i)
304  ["blksize"]=>
305  int(%i)
306  ["blocks"]=>
307  int(%i)
308}
309bool(true)
310Done
311