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
14/* Prototype  : proto bool touch(string filename [, int time [, int atime]])
15 * Description: Set modification time of file
16 * Source code: ext/standard/filestat.c
17 * Alias to functions:
18 */
19
20echo "*** Testing touch() : basic functionality ***\n";
21
22$filename = __DIR__."/touch_basic.dat";
23
24echo "\n--- testing touch creates a file ---\n";
25@unlink($filename);
26if (file_exists($filename)) {
27   die("touch_basic failed");
28}
29var_dump( touch($filename) );
30if (file_exists($filename) == false) {
31   die("touch_basic failed");
32}
33
34echo "\n --- testing touch doesn't alter file contents ---\n";
35$testln = "Here is a test line";
36$h = fopen($filename, "wb");
37fwrite($h, $testln);
38fclose($h);
39touch($filename);
40$h = fopen($filename, "rb");
41echo fgets($h);
42fclose($h);
43
44echo "\n\n --- testing touch alters the correct file metadata ---\n";
45$init_meta = stat($filename);
46clearstatcache();
47sleep(1);
48touch($filename);
49$next_meta = stat($filename);
50$type = array("dev", "ino", "mode", "nlink", "uid", "gid",
51              "rdev", "size", "atime", "mtime", "ctime",
52              "blksize", "blocks");
53
54for ($i = 0; $i < count($type); $i++) {
55   if ($init_meta[$i] != $next_meta[$i]) {
56      echo "stat data differs at $type[$i]\n";
57   }
58}
59
60
61// Initialise all required variables
62$time = 10000;
63$atime = 20470;
64
65// Calling touch() with all possible arguments
66echo "\n --- testing touch using all parameters ---\n";
67var_dump( touch($filename, $time, $atime) );
68clearstatcache();
69$init_meta = stat($filename);
70echo "ctime=".$init_meta['ctime']."\n";
71echo "mtime=".$init_meta['mtime']."\n";
72echo "atime=".$init_meta['atime']."\n";
73
74unlink($filename);
75
76echo "Done";
77?>
78--EXPECTF--
79*** Testing touch() : basic functionality ***
80
81--- testing touch creates a file ---
82bool(true)
83
84 --- testing touch doesn't alter file contents ---
85Here is a test line
86
87 --- testing touch alters the correct file metadata ---
88stat data differs at atime
89stat data differs at mtime
90stat data differs at ctime
91
92 --- testing touch using all parameters ---
93bool(true)
94ctime=%d
95mtime=10000
96atime=20470
97Done
98