005_variation-win32.phpt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 Windows-only test');
  7. }
  8. if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
  9. ?>
  10. --FILE--
  11. <?php
  12. function stat_fn( $filename ) {
  13. echo "-- File access time is => ";
  14. print( @date( 'Y:M:D:H:i:s', fileatime($filename) ) )."\n";
  15. clearstatcache();
  16. echo "-- File modification time is => ";
  17. print( @date( 'Y:M:D:H:i:s', filemtime($filename) ) )."\n";
  18. clearstatcache();
  19. echo "-- inode change time is => ";
  20. print( @date( 'Y:M:D:H:i:s', filectime($filename) ) )."\n";
  21. clearstatcache();
  22. }
  23. echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n";
  24. $file_path = __DIR__;
  25. // create files
  26. $file_handle = fopen("$file_path/005_variation1.tmp", "w");
  27. fclose($file_handle);
  28. stat_fn("$file_path/005_variation1.tmp");
  29. sleep(1);
  30. $file_handle = fopen("$file_path/005_variation2.tmp", "w");
  31. fclose($file_handle);
  32. stat_fn("$file_path/005_variation2.tmp");
  33. sleep(1);
  34. $file_handle = fopen("$file_path/005_variation3.tmp", "w");
  35. fclose($file_handle);
  36. stat_fn("$file_path/005_variation3.tmp");
  37. // delete files
  38. unlink("$file_path/005_variation1.tmp");
  39. unlink("$file_path/005_variation2.tmp");
  40. unlink("$file_path/005_variation3.tmp");
  41. echo "\n-- Checking different times, just after creating the file --\n";
  42. $file_name = "$file_path/005_variation1.tmp";
  43. $file_write_handle = fopen($file_name, "w");
  44. fclose($file_write_handle);
  45. stat_fn($file_name);
  46. sleep(1);
  47. /* filectime + 2 */
  48. echo "\n-- Checking different times, after changing the file permission --\n";
  49. chmod($file_name, 0777);
  50. stat_fn($file_name);
  51. sleep(1);
  52. /* filemtime + 2 & filectime + 2 */
  53. echo "\n-- Checking different times, after writing into the file --\n";
  54. $file_write_handle = fopen($file_name, "w");
  55. fwrite($file_write_handle, "Hello, world");
  56. fclose($file_write_handle);
  57. stat_fn($file_name);
  58. sleep(1);
  59. /* fileatime + 2 */
  60. echo "\n-- Checking different times, after reading from the file --\n";
  61. $file_read_handle = fopen($file_name ,"r");
  62. fread($file_read_handle, 10);
  63. fclose( $file_read_handle);
  64. stat_fn($file_name);
  65. sleep(1);
  66. /* No change */
  67. echo "\n-- Checking same times, after creating a softlink to the file --\n";
  68. symlink($file_name, "$file_path/005_variation_softlink.tmp");
  69. stat_fn($file_name);
  70. sleep(1);
  71. /* filectime + 2 */
  72. echo "\n-- Checking different times, after creating a hardlink to the file --\n";
  73. link($file_name, "$file_path/005_variation_hardlink.tmp");
  74. stat_fn($file_name);
  75. sleep(1);
  76. /* No change */
  77. echo "\n-- Checking same times, after making a copy of the file --\n";
  78. $file_copy = "$file_path/005_variation_copy.tmp";
  79. copy($file_name, $file_copy);
  80. stat_fn($file_name);
  81. sleep(1);
  82. /* fileatime + 2 */
  83. echo "\n-- Checking different times, after performing is_file() operation on the file --\n";
  84. is_file($file_name);
  85. stat_fn($file_name);
  86. sleep(1);
  87. echo "\n*** Testing touch() function with different time values ***\n";
  88. $file_name2 = $file_path."/005_variation_touch.tmp";
  89. $file_handle = fopen($file_name2, "w");
  90. fclose($file_handle);
  91. sleep(1);
  92. /* Time is not mentioned */
  93. var_dump( touch($file_name2) ); //set to current system time
  94. stat_fn($file_name2);
  95. sleep(1);
  96. /* set to access(creation time of the file) time */
  97. var_dump( touch($file_name2, @date(fileatime($file_name2))) );
  98. stat_fn($file_name2);
  99. sleep(1);
  100. /* set to access time of $file_name2 */
  101. var_dump( touch($file_path."/005_variation_touch_fly.tmp", @date(fileatime($file_name2)), time()) );
  102. stat_fn($file_name2);
  103. sleep(1);
  104. /* set to default value, with Invalid timestamps */
  105. var_dump( touch($file_name2, 10) );
  106. stat_fn($file_name2);
  107. var_dump( touch($file_name2, 10, 20) );
  108. stat_fn($file_name2);
  109. /* touch() after renaming the file */
  110. rename($file_name2, "$file_path/005_variation_touch_new.tmp");
  111. stat_fn("$file_path/005_variation_touch_new.tmp");
  112. echo "Done\n";
  113. ?>
  114. --CLEAN--
  115. <?php
  116. $file_path = __DIR__;
  117. unlink($file_path."/005_variation_softlink.tmp");
  118. unlink($file_path."/005_variation_hardlink.tmp");
  119. unlink($file_path."/005_variation1.tmp");
  120. unlink($file_path."/005_variation_copy.tmp");
  121. unlink($file_path."/005_variation_touch.tmp");
  122. unlink($file_path."/005_variation_touch_fly.tmp");
  123. unlink($file_path."/005_variation_touch_new.tmp");
  124. ?>
  125. --EXPECTF--
  126. *** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***
  127. -- File access time is => %d:%s:%s:%d:%d:%d
  128. -- File modification time is => %d:%s:%s:%d:%d:%d
  129. -- inode change time is => %d:%s:%s:%d:%d:%d
  130. -- File access time is => %d:%s:%s:%d:%d:%d
  131. -- File modification time is => %d:%s:%s:%d:%d:%d
  132. -- inode change time is => %d:%s:%s:%d:%d:%d
  133. -- File access time is => %d:%s:%s:%d:%d:%d
  134. -- File modification time is => %d:%s:%s:%d:%d:%d
  135. -- inode change time is => %d:%s:%s:%d:%d:%d
  136. -- Checking different times, just after creating the file --
  137. -- File access time is => %d:%s:%s:%d:%d:%d
  138. -- File modification time is => %d:%s:%s:%d:%d:%d
  139. -- inode change time is => %d:%s:%s:%d:%d:%d
  140. -- Checking different times, after changing the file permission --
  141. -- File access time is => %d:%s:%s:%d:%d:%d
  142. -- File modification time is => %d:%s:%s:%d:%d:%d
  143. -- inode change time is => %d:%s:%s:%d:%d:%d
  144. -- Checking different times, after writing into the file --
  145. -- File access time is => %d:%s:%s:%d:%d:%d
  146. -- File modification time is => %d:%s:%s:%d:%d:%d
  147. -- inode change time is => %d:%s:%s:%d:%d:%d
  148. -- Checking different times, after reading from the file --
  149. -- File access time is => %d:%s:%s:%d:%d:%d
  150. -- File modification time is => %d:%s:%s:%d:%d:%d
  151. -- inode change time is => %d:%s:%s:%d:%d:%d
  152. -- Checking same times, after creating a softlink to the file --
  153. -- File access time is => %d:%s:%s:%d:%d:%d
  154. -- File modification time is => %d:%s:%s:%d:%d:%d
  155. -- inode change time is => %d:%s:%s:%d:%d:%d
  156. -- Checking different times, after creating a hardlink to the file --
  157. -- File access time is => %d:%s:%s:%d:%d:%d
  158. -- File modification time is => %d:%s:%s:%d:%d:%d
  159. -- inode change time is => %d:%s:%s:%d:%d:%d
  160. -- Checking same times, after making a copy of the file --
  161. -- File access time is => %d:%s:%s:%d:%d:%d
  162. -- File modification time is => %d:%s:%s:%d:%d:%d
  163. -- inode change time is => %d:%s:%s:%d:%d:%d
  164. -- Checking different times, after performing is_file() operation on the file --
  165. -- File access time is => %d:%s:%s:%d:%d:%d
  166. -- File modification time is => %d:%s:%s:%d:%d:%d
  167. -- inode change time is => %d:%s:%s:%d:%d:%d
  168. *** Testing touch() function with different time values ***
  169. bool(true)
  170. -- File access time is => %d:%s:%s:%d:%d:%d
  171. -- File modification time is => %d:%s:%s:%d:%d:%d
  172. -- inode change time is => %d:%s:%s:%d:%d:%d
  173. bool(true)
  174. -- File access time is => %d:%s:%s:%d:%d:%d
  175. -- File modification time is => %d:%s:%s:%d:%d:%d
  176. -- inode change time is => %d:%s:%s:%d:%d:%d
  177. bool(true)
  178. -- File access time is => %d:%s:%s:%d:%d:%d
  179. -- File modification time is => %d:%s:%s:%d:%d:%d
  180. -- inode change time is => %d:%s:%s:%d:%d:%d
  181. bool(true)
  182. -- File access time is => %d:%s:%s:%d:%d:%d
  183. -- File modification time is => %d:%s:%s:%d:%d:%d
  184. -- inode change time is => %d:%s:%s:%d:%d:%d
  185. bool(true)
  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. Done