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