touch_basic-win32.phpt 2.2 KB

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