1--TEST-- 2Test touch() function : basic functionality 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); 8if (substr(PHP_OS, 0, 3) == 'WIN') { 9 die('skip.. only for Non Windows'); 10} 11?> 12--FILE-- 13<?php 14echo "*** Testing touch() : basic functionality ***\n"; 15 16$filename = __DIR__."/touch_basic.dat"; 17 18echo "\n--- testing touch creates a file ---\n"; 19@unlink($filename); 20if (file_exists($filename)) { 21 die("touch_basic failed"); 22} 23var_dump( touch($filename) ); 24if (file_exists($filename) == false) { 25 die("touch_basic failed"); 26} 27 28echo "\n --- testing touch doesn't alter file contents ---\n"; 29$testln = "Here is a test line"; 30$h = fopen($filename, "wb"); 31fwrite($h, $testln); 32fclose($h); 33touch($filename); 34$h = fopen($filename, "rb"); 35echo fgets($h); 36fclose($h); 37 38echo "\n\n --- testing touch alters the correct file metadata ---\n"; 39$init_meta = stat($filename); 40clearstatcache(); 41sleep(1); 42touch($filename); 43$next_meta = stat($filename); 44$type = array("dev", "ino", "mode", "nlink", "uid", "gid", 45 "rdev", "size", "atime", "mtime", "ctime", 46 "blksize", "blocks"); 47 48for ($i = 0; $i < count($type); $i++) { 49 if ($init_meta[$i] != $next_meta[$i]) { 50 echo "stat data differs at $type[$i]\n"; 51 } 52} 53 54 55// Initialise all required variables 56$time = 10000; 57$atime = 20470; 58 59// Calling touch() with all possible arguments 60echo "\n --- testing touch using all parameters ---\n"; 61var_dump( touch($filename, $time, $atime) ); 62clearstatcache(); 63$init_meta = stat($filename); 64echo "ctime=".$init_meta['ctime']."\n"; 65echo "mtime=".$init_meta['mtime']."\n"; 66echo "atime=".$init_meta['atime']."\n"; 67 68unlink($filename); 69 70echo "Done"; 71?> 72--EXPECTF-- 73*** Testing touch() : basic functionality *** 74 75--- testing touch creates a file --- 76bool(true) 77 78 --- testing touch doesn't alter file contents --- 79Here is a test line 80 81 --- testing touch alters the correct file metadata --- 82stat data differs at atime 83stat data differs at mtime 84stat data differs at ctime 85 86 --- testing touch using all parameters --- 87bool(true) 88ctime=%d 89mtime=10000 90atime=20470 91Done 92