xref: /PHP-8.2/ext/standard/tests/file/touch.phpt (revision 25f1c405)
1--TEST--
2touch() tests
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. only for Non Windows.');
7}
8?>
9--FILE--
10<?php
11
12// This doesn't work for windows, time, atime usage results in very different
13// output to linux. This could be a php.net bug on windows or a windows querk.
14$filename = __DIR__."/touch.dat";
15
16var_dump(touch($filename));
17var_dump(filemtime($filename));
18@unlink($filename);
19var_dump(touch($filename, 101));
20var_dump(filemtime($filename));
21
22@unlink($filename);
23var_dump(touch($filename, -1));
24var_dump(filemtime($filename));
25
26@unlink($filename);
27var_dump(touch($filename, 100, 100));
28var_dump(filemtime($filename));
29
30@unlink($filename);
31var_dump(touch($filename, 100, -100));
32var_dump(filemtime($filename));
33
34var_dump(touch("/no/such/file/or/directory"));
35
36@unlink($filename);
37
38try {
39    touch("/no/such/file/or/directory", null, 1599492068);
40} catch (ValueError $exception) {
41    echo $exception->getMessage() . "\n";
42}
43
44echo "Done\n";
45?>
46--EXPECTF--
47bool(true)
48int(%d)
49bool(true)
50int(101)
51bool(true)
52int(%i)
53bool(true)
54int(100)
55bool(true)
56int(100)
57
58Warning: touch(): Unable to create file /no/such/file/or/directory because %s in %s on line %d
59bool(false)
60touch(): Argument #2 ($mtime) cannot be null when argument #3 ($atime) is an integer
61Done
62