touch_basic.phpt 2.3 KB

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