1--TEST--
2Test stat() function: basic functionality
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip.. valid only for Windows');
7}
8?>
9--FILE--
10<?php
11/*
12   Prototype: array stat ( string $filename );
13   Description: Gives information about a file
14*/
15
16$file_path = dirname(__FILE__);
17require("$file_path/file.inc");
18
19echo "*** Testing stat() : basic functionality ***\n";
20
21/* creating temp directory and file */
22
23// creating dir
24$dirname = "$file_path/stat_basic_私はガラスを食べられます";
25mkdir($dirname);
26// stat of the dir created
27$dir_stat = stat($dirname);
28clearstatcache();
29sleep(2);
30
31// creating file
32$filename = "$dirname/stat_basic_私はガラスを食べられます.tmp";
33$file_handle = fopen($filename, "w");
34fclose($file_handle);
35// stat of the file created
36$file_stat = stat($filename);
37sleep(2);
38
39// now new stat of the dir after file is created
40$new_dir_stat = stat($dirname);
41clearstatcache();
42
43// stat contains 13 different values stored twice, can be accessed using
44// numeric and named keys, compare them to see they are same
45echo "*** Testing stat(): validating the values stored in stat ***\n";
46// Initial stat values
47var_dump( compare_self_stat($file_stat) ); //expect true
48var_dump( compare_self_stat($dir_stat) );  //expect true
49
50// New stat values taken after creation of file
51var_dump( compare_self_stat($new_dir_stat) );  // expect true
52
53// compare the two stat values, initial stat and stat recorded after
54// creating file, also dump the value of stats
55echo "*** Testing stat(): comparing stats (recorded before and after file creation) ***\n";
56echo "-- comparing difference in dir stats before and after creating file in it --\n";
57$affected_elements = array( 9, 'mtime' );
58var_dump( compare_stats($dir_stat, $new_dir_stat, $affected_elements, '!=', true) ); // expect true
59
60echo "*** Testing stat(): for the return value ***\n";
61var_dump( is_array( stat($filename) ) );
62
63echo "\n---Done---";
64?>
65--CLEAN--
66<?php
67$file_path = dirname(__FILE__);
68unlink("$file_path/stat_basic_私はガラスを食べられます/stat_basic_私はガラスを食べられます.tmp");
69rmdir("$file_path/stat_basic_私はガラスを食べられます");
70?>
71--EXPECTF--
72*** Testing stat() : basic functionality ***
73*** Testing stat(): validating the values stored in stat ***
74bool(true)
75bool(true)
76bool(true)
77*** Testing stat(): comparing stats (recorded before and after file creation) ***
78-- comparing difference in dir stats before and after creating file in it --
79array(26) {
80  [0]=>
81  int(%d)
82  [1]=>
83  int(0)
84  [2]=>
85  int(%d)
86  [3]=>
87  int(%d)
88  [4]=>
89  int(0)
90  [5]=>
91  int(0)
92  [6]=>
93  int(%d)
94  [7]=>
95  int(%d)
96  [8]=>
97  int(%d)
98  [9]=>
99  int(%d)
100  [10]=>
101  int(%d)
102  [11]=>
103  int(-1)
104  [12]=>
105  int(-1)
106  ["dev"]=>
107  int(%d)
108  ["ino"]=>
109  int(0)
110  ["mode"]=>
111  int(%d)
112  ["nlink"]=>
113  int(%d)
114  ["uid"]=>
115  int(0)
116  ["gid"]=>
117  int(0)
118  ["rdev"]=>
119  int(%d)
120  ["size"]=>
121  int(%d)
122  ["atime"]=>
123  int(%d)
124  ["mtime"]=>
125  int(%d)
126  ["ctime"]=>
127  int(%d)
128  ["blksize"]=>
129  int(-1)
130  ["blocks"]=>
131  int(-1)
132}
133array(26) {
134  [0]=>
135  int(%d)
136  [1]=>
137  int(%d)
138  [2]=>
139  int(%d)
140  [3]=>
141  int(%d)
142  [4]=>
143  int(%d)
144  [5]=>
145  int(%d)
146  [6]=>
147  int(%d)
148  [7]=>
149  int(%d)
150  [8]=>
151  int(%d)
152  [9]=>
153  int(%d)
154  [10]=>
155  int(%d)
156  [11]=>
157  int(-1)
158  [12]=>
159  int(-1)
160  ["dev"]=>
161  int(%d)
162  ["ino"]=>
163  int(%d)
164  ["mode"]=>
165  int(%d)
166  ["nlink"]=>
167  int(%d)
168  ["uid"]=>
169  int(%d)
170  ["gid"]=>
171  int(%d)
172  ["rdev"]=>
173  int(%d)
174  ["size"]=>
175  int(%d)
176  ["atime"]=>
177  int(%d)
178  ["mtime"]=>
179  int(%d)
180  ["ctime"]=>
181  int(%d)
182  ["blksize"]=>
183  int(-1)
184  ["blocks"]=>
185  int(-1)
186}
187bool(true)
188*** Testing stat(): for the return value ***
189bool(true)
190
191---Done---
192