Annotation of embedaddon/php/ext/standard/tests/file/005_variation.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fileatime(), filemtime(), filectime() & touch() functions : usage variation
3: --SKIPIF--
4: <?php
5: if (substr(PHP_OS, 0, 3) == 'WIN') {
6: die('skip Do not run on Windows');
7: }
8: if (getenv("SKIP_SLOW_TESTS")) {
9: die("skip slow test");
10: }
11: ?>
12: --FILE--
13: <?php
14: /*
15: Prototype: int fileatime ( string $filename );
16: Description: Returns the time the file was last accessed, or FALSE
17: in case of an error. The time is returned as a Unix timestamp.
18:
19: Prototype: int filemtime ( string $filename );
20: Description: Returns the time the file was last modified, or FALSE
21: in case of an error.
22:
23: Prototype: int filectime ( string $filename );
24: Description: Returns the time the file was last changed, or FALSE
25: in case of an error. The time is returned as a Unix timestamp.
26:
27: Prototype: bool touch ( string $filename [, int $time [, int $atime]] );
28: Description: Attempts to set the access and modification times of the file
29: named in the filename parameter to the value given in time.
30: */
31:
32: /*
33: Prototype: void stat_fn(string $filename);
34: Description: Prints access, modification and change times of a file
35: */
36: function stat_fn( $filename ) {
37: echo "-- File access time is => ";
38: print( @date( 'Y:M:D:H:i:s', fileatime($filename) ) )."\n";
39: clearstatcache();
40: echo "-- File modification time is => ";
41: print( @date( 'Y:M:D:H:i:s', filemtime($filename) ) )."\n";
42: clearstatcache();
43: echo "-- inode change time is => ";
44: print( @date( 'Y:M:D:H:i:s', filectime($filename) ) )."\n";
45: clearstatcache();
46:
47: }
48:
49: echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n";
50: $file_path = dirname(__FILE__);
51: // create files
52: $file_handle = fopen("$file_path/005_variation1.tmp", "w");
53: fclose($file_handle);
54: stat_fn("$file_path/005_variation1.tmp");
55: sleep(2);
56:
57: $file_handle = fopen("$file_path/005_variation2.tmp", "w");
58: fclose($file_handle);
59: stat_fn("$file_path/005_variation2.tmp");
60: sleep(2);
61:
62: $file_handle = fopen("$file_path/005_variation3.tmp", "w");
63: fclose($file_handle);
64: stat_fn("$file_path/005_variation3.tmp");
65:
66: // delete files
67: unlink("$file_path/005_variation1.tmp");
68: unlink("$file_path/005_variation2.tmp");
69: unlink("$file_path/005_variation3.tmp");
70:
71: echo "\n-- Checking different times, just after creating the file --\n";
72: $file_name = "$file_path/005_variation1.tmp";
73: $file_write_handle = fopen($file_name, "w");
74: fclose($file_write_handle);
75: stat_fn($file_name);
76: sleep(2);
77:
78: /* filectime + 2 */
79: echo "\n-- Checking different times, after changing the file permission --\n";
80: chmod($file_name, 0777);
81: stat_fn($file_name);
82: sleep(2);
83:
84: /* filemtime + 2 & filectime + 2 */
85: echo "\n-- Checking different times, after writing into the file --\n";
86: $file_write_handle = fopen($file_name, "w");
87: fwrite($file_write_handle, "Hello, world");
88: fclose($file_write_handle);
89: stat_fn($file_name);
90: sleep(2);
91:
92: /* fileatime + 2 */
93: echo "\n-- Checking different times, after reading from the file --\n";
94: $file_read_handle = fopen($file_name ,"r");
95: fread($file_read_handle, 10);
96: fclose( $file_read_handle);
97: stat_fn($file_name);
98: sleep(2);
99:
100: /* No change */
101: echo "\n-- Checking different times, after creating a softlink to the file --\n";
102: symlink($file_name, "$file_path/005_variation_softlink.tmp");
103: stat_fn($file_name);
104: sleep(2);
105:
106: /* filectime + 2 */
107: echo "\n-- Checking different times, after creating a hardlink to the file --\n";
108: link($file_name, "$file_path/005_variation_hardlink.tmp");
109: stat_fn($file_name);
110: sleep(2);
111:
112: /* No change */
113: echo "\n-- Checking different times, after making a copy of the file --\n";
114: $file_copy = "$file_path/005_variation_copy.tmp";
115: copy($file_name, $file_copy);
116: stat_fn($file_name);
117: sleep(2);
118:
119: /* fileatime + 2 */
120: echo "\n-- Checking different times, after performing is_file() operation on the file --\n";
121: is_file($file_name);
122: stat_fn($file_name);
123: sleep(2);
124:
125:
126: echo "\n*** Testing touch() function with different time values ***\n";
127: $file_name2 = $file_path."/005_variation_touch.tmp";
128: $file_handle = fopen($file_name2, "w");
129: fclose($file_handle);
130: sleep(2);
131:
132: /* Time is not mentioned */
133: var_dump( touch($file_name2) ); //set to current system time
134: stat_fn($file_name2);
135: sleep(2);
136:
137: /* set to access(creation time of the file) time */
138: var_dump( touch($file_name2, @date(fileatime($file_name2))) );
139: stat_fn($file_name2);
140: sleep(2);
141:
142: /* set to access time of $file_name2 */
143: var_dump( touch($file_path."/005_variation_touch_fly.tmp", @date(fileatime($file_name2)), time()) );
144: stat_fn($file_name2);
145: sleep(2);
146:
147: /* set to default value, with Invalid timestamps */
148: var_dump( touch($file_name2, 10) );
149: stat_fn($file_name2);
150: var_dump( touch($file_name2, 10, 20) );
151: stat_fn($file_name2);
152:
153: /* touch() after renaming the file */
154: rename($file_name2, "$file_path/005_variation_touch_new.tmp");
155: stat_fn("$file_path/005_variation_touch_new.tmp");
156:
157: echo "Done\n";
158: ?>
159: --CLEAN--
160: <?php
161: $file_path = dirname(__FILE__);
162: if(file_exists($file_path."/005_variation_softlink.tmp")) {
163: unlink($file_path."/005_variation_softlink.tmp");
164: }
165: if(file_exists($file_path."/005_variation_hardlink.tmp")) {
166: unlink($file_path."/005_variation_hardlink.tmp");
167: }
168: if(file_exists($file_path."/005_variation1.tmp")) {
169: unlink($file_path."/005_variation1.tmp");
170: }
171: if(file_exists($file_path."/005_variation_copy.tmp")) {
172: unlink($file_path."/005_variation_copy.tmp");
173: }
174: if(file_exists($file_path."/005_variation_touch.tmp")) {
175: unlink($file_path."/005_variation_touch.tmp");
176: }
177: if(file_exists($file_path."/005_variation_touch_fly.tmp")) {
178: unlink($file_path."/005_variation_touch_fly.tmp");
179: }
180: if(file_exists($file_path."/005_variation_touch_new.tmp")) {
181: unlink($file_path."/005_variation_touch_new.tmp");
182: }
183: ?>
184: --EXPECTF--
185: *** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***
186: -- File access time is => %d:%s:%s:%d:%d:%d
187: -- File modification time is => %d:%s:%s:%d:%d:%d
188: -- inode change time is => %d:%s:%s:%d:%d:%d
189: -- File access time is => %d:%s:%s:%d:%d:%d
190: -- File modification time is => %d:%s:%s:%d:%d:%d
191: -- inode change time is => %d:%s:%s:%d:%d:%d
192: -- File access time is => %d:%s:%s:%d:%d:%d
193: -- File modification time is => %d:%s:%s:%d:%d:%d
194: -- inode change time is => %d:%s:%s:%d:%d:%d
195:
196: -- Checking different times, just after creating the file --
197: -- File access time is => %d:%s:%s:%d:%d:%d
198: -- File modification time is => %d:%s:%s:%d:%d:%d
199: -- inode change time is => %d:%s:%s:%d:%d:%d
200:
201: -- Checking different times, after changing the file permission --
202: -- File access time is => %d:%s:%s:%d:%d:%d
203: -- File modification time is => %d:%s:%s:%d:%d:%d
204: -- inode change time is => %d:%s:%s:%d:%d:%d
205:
206: -- Checking different times, after writing into the file --
207: -- File access time is => %d:%s:%s:%d:%d:%d
208: -- File modification time is => %d:%s:%s:%d:%d:%d
209: -- inode change time is => %d:%s:%s:%d:%d:%d
210:
211: -- Checking different times, after reading from the file --
212: -- File access time is => %d:%s:%s:%d:%d:%d
213: -- File modification time is => %d:%s:%s:%d:%d:%d
214: -- inode change time is => %d:%s:%s:%d:%d:%d
215:
216: -- Checking different times, after creating a softlink to the file --
217: -- File access time is => %d:%s:%s:%d:%d:%d
218: -- File modification time is => %d:%s:%s:%d:%d:%d
219: -- inode change time is => %d:%s:%s:%d:%d:%d
220:
221: -- Checking different times, after creating a hardlink to the file --
222: -- File access time is => %d:%s:%s:%d:%d:%d
223: -- File modification time is => %d:%s:%s:%d:%d:%d
224: -- inode change time is => %d:%s:%s:%d:%d:%d
225:
226: -- Checking different times, after making a copy of the file --
227: -- File access time is => %d:%s:%s:%d:%d:%d
228: -- File modification time is => %d:%s:%s:%d:%d:%d
229: -- inode change time is => %d:%s:%s:%d:%d:%d
230:
231: -- Checking different times, after performing is_file() operation on the file --
232: -- File access time is => %d:%s:%s:%d:%d:%d
233: -- File modification time is => %d:%s:%s:%d:%d:%d
234: -- inode change time is => %d:%s:%s:%d:%d:%d
235:
236: *** Testing touch() function with different time values ***
237: bool(true)
238: -- File access time is => %d:%s:%s:%d:%d:%d
239: -- File modification time is => %d:%s:%s:%d:%d:%d
240: -- inode change time is => %d:%s:%s:%d:%d:%d
241: bool(true)
242: -- File access time is => %d:%s:%s:%d:%d:%d
243: -- File modification time is => %d:%s:%s:%d:%d:%d
244: -- inode change time is => %d:%s:%s:%d:%d:%d
245: bool(true)
246: -- File access time is => %d:%s:%s:%d:%d:%d
247: -- File modification time is => %d:%s:%s:%d:%d:%d
248: -- inode change time is => %d:%s:%s:%d:%d:%d
249: bool(true)
250: -- File access time is => %d:%s:%s:%d:%d:%d
251: -- File modification time is => %d:%s:%s:%d:%d:%d
252: -- inode change time is => %d:%s:%s:%d:%d:%d
253: bool(true)
254: -- File access time is => %d:%s:%s:%d:%d:%d
255: -- File modification time is => %d:%s:%s:%d:%d:%d
256: -- inode change time is => %d:%s:%s:%d:%d:%d
257: -- File access time is => %d:%s:%s:%d:%d:%d
258: -- File modification time is => %d:%s:%s:%d:%d:%d
259: -- inode change time is => %d:%s:%s:%d:%d:%d
260: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>