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