005_variation-win32.phpt 7.3 KB

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