touch_variation4.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. --TEST--
  2. Test touch() function : usage variation - different types for atime
  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.. Not for Windows');
  9. }
  10. ?>
  11. --FILE--
  12. <?php
  13. /* Prototype : 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() : usage variation ***\n";
  19. // Define error handler
  20. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  21. if (error_reporting() != 0) {
  22. // report non-silenced errors
  23. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  24. }
  25. }
  26. set_error_handler('test_error_handler');
  27. // Initialise function arguments not being substituted (if any)
  28. $filename = 'touchVar3.tmp';
  29. $time = 10;
  30. //get an unset variable
  31. $unset_var = 10;
  32. unset ($unset_var);
  33. // define some classes
  34. class classWithToString
  35. {
  36. public function __toString() {
  37. return "Class A object";
  38. }
  39. }
  40. class classWithoutToString
  41. {
  42. }
  43. // heredoc string
  44. $heredoc = <<<EOT
  45. hello world
  46. EOT;
  47. // add arrays
  48. $index_array = array (1, 2, 3);
  49. $assoc_array = array ('one' => 1, 'two' => 2);
  50. //array of values to iterate over
  51. $inputs = array(
  52. // float data
  53. 'float 10.5' => 10.5,
  54. 'float 12.3456789000e10' => 12.3456789000e10,
  55. 'float .5' => .5,
  56. // array data
  57. 'empty array' => array(),
  58. 'int indexed array' => $index_array,
  59. 'associative array' => $assoc_array,
  60. 'nested arrays' => array('foo', $index_array, $assoc_array),
  61. // null data
  62. 'uppercase NULL' => NULL,
  63. 'lowercase null' => null,
  64. // boolean data
  65. 'lowercase true' => true,
  66. 'lowercase false' =>false,
  67. 'uppercase TRUE' =>TRUE,
  68. 'uppercase FALSE' =>FALSE,
  69. // empty data
  70. 'empty string DQ' => "",
  71. 'empty string SQ' => '',
  72. // string data
  73. 'string DQ' => "string",
  74. 'string SQ' => 'string',
  75. 'mixed case string' => "sTrInG",
  76. 'heredoc' => $heredoc,
  77. // object data
  78. 'instance of classWithToString' => new classWithToString(),
  79. 'instance of classWithoutToString' => new classWithoutToString(),
  80. // undefined data
  81. 'undefined var' => @$undefined_var,
  82. // unset data
  83. 'unset var' => @$unset_var,
  84. );
  85. // loop through each element of the array for atime
  86. foreach($inputs as $key =>$value) {
  87. echo "\n--$key--\n";
  88. var_dump( touch($filename, $time, $value) );
  89. };
  90. unlink($filename);
  91. ?>
  92. ===DONE===
  93. --EXPECTF--
  94. *** Testing touch() : usage variation ***
  95. --float 10.5--
  96. bool(true)
  97. --float 12.3456789000e10--
  98. bool(true)
  99. --float .5--
  100. bool(true)
  101. --empty array--
  102. Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d)
  103. NULL
  104. --int indexed array--
  105. Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d)
  106. NULL
  107. --associative array--
  108. Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d)
  109. NULL
  110. --nested arrays--
  111. Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d)
  112. NULL
  113. --uppercase NULL--
  114. bool(true)
  115. --lowercase null--
  116. bool(true)
  117. --lowercase true--
  118. bool(true)
  119. --lowercase false--
  120. bool(true)
  121. --uppercase TRUE--
  122. bool(true)
  123. --uppercase FALSE--
  124. bool(true)
  125. --empty string DQ--
  126. Error: 2 - touch() expects parameter 3 to be long, string given, %s(%d)
  127. NULL
  128. --empty string SQ--
  129. Error: 2 - touch() expects parameter 3 to be long, string given, %s(%d)
  130. NULL
  131. --string DQ--
  132. Error: 2 - touch() expects parameter 3 to be long, string given, %s(%d)
  133. NULL
  134. --string SQ--
  135. Error: 2 - touch() expects parameter 3 to be long, string given, %s(%d)
  136. NULL
  137. --mixed case string--
  138. Error: 2 - touch() expects parameter 3 to be long, string given, %s(%d)
  139. NULL
  140. --heredoc--
  141. Error: 2 - touch() expects parameter 3 to be long, string given, %s(%d)
  142. NULL
  143. --instance of classWithToString--
  144. Error: 2 - touch() expects parameter 3 to be long, object given, %s(%d)
  145. NULL
  146. --instance of classWithoutToString--
  147. Error: 2 - touch() expects parameter 3 to be long, object given, %s(%d)
  148. NULL
  149. --undefined var--
  150. bool(true)
  151. --unset var--
  152. bool(true)
  153. ===DONE===