DateTime_modify_variation1.phpt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. --TEST--
  2. Test DateTime::modify() function : usage variation - Passing unexpected values to first argument $modify.
  3. --FILE--
  4. <?php
  5. /* Prototype : public DateTime DateTime::modify ( string $modify )
  6. * Description: Alter the timestamp of a DateTime object by incrementing or decrementing in a format accepted by strtotime().
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions: public date_modify()
  9. */
  10. echo "*** Testing DateTime::modify() : usage variation - unexpected values to first argument \$modify***\n";
  11. //Set the default time zone
  12. date_default_timezone_set("Europe/London");
  13. //get an unset variable
  14. $unset_var = 10;
  15. unset ($unset_var);
  16. // define some classes
  17. class classWithToString
  18. {
  19. public function __toString() {
  20. return "Class A object";
  21. }
  22. }
  23. class classWithoutToString
  24. {
  25. }
  26. // heredoc string
  27. $heredoc = <<<EOT
  28. hello world
  29. EOT;
  30. // add arrays
  31. $index_array = array (1, 2, 3);
  32. $assoc_array = array ('one' => 1, 'two' => 2);
  33. // resource
  34. $file_handle = fopen(__FILE__, 'r');
  35. //array of values to iterate over
  36. $inputs = array(
  37. // int data
  38. 'int 0' => 0,
  39. 'int 1' => 1,
  40. 'int 12345' => 12345,
  41. 'int -12345' => -12345,
  42. // float data
  43. 'float 10.5' => 10.5,
  44. 'float -10.5' => -10.5,
  45. 'float .5' => .5,
  46. // array data
  47. 'empty array' => array(),
  48. 'int indexed array' => $index_array,
  49. 'associative array' => $assoc_array,
  50. 'nested arrays' => array('foo', $index_array, $assoc_array),
  51. // null data
  52. 'uppercase NULL' => NULL,
  53. 'lowercase null' => null,
  54. // boolean data
  55. 'lowercase true' => true,
  56. 'lowercase false' =>false,
  57. 'uppercase TRUE' =>TRUE,
  58. 'uppercase FALSE' =>FALSE,
  59. // empty data
  60. 'empty string DQ' => "",
  61. 'empty string SQ' => '',
  62. // string data
  63. 'string DQ' => "string",
  64. 'string SQ' => 'string',
  65. 'mixed case string' => "sTrInG",
  66. 'heredoc' => $heredoc,
  67. // object data
  68. 'instance of classWithToString' => new classWithToString(),
  69. 'instance of classWithoutToString' => new classWithoutToString(),
  70. // undefined data
  71. 'undefined var' => @$undefined_var,
  72. // unset data
  73. 'unset var' => @$unset_var,
  74. // resource
  75. 'resource' => $file_handle
  76. );
  77. $object = new DateTime("2009-01-31 14:28:41");
  78. foreach($inputs as $variation =>$format) {
  79. echo "\n-- $variation --\n";
  80. var_dump( $object->modify($format) );
  81. };
  82. // closing the resource
  83. fclose( $file_handle );
  84. ?>
  85. ===DONE===
  86. --EXPECTF--
  87. *** Testing DateTime::modify() : usage variation - unexpected values to first argument $modify***
  88. -- int 0 --
  89. Warning: DateTime::modify(): Failed to parse time string (0) at position 0 (0): Unexpected character in %sDateTime_modify_variation1.php on line 99
  90. bool(false)
  91. -- int 1 --
  92. Warning: DateTime::modify(): Failed to parse time string (1) at position 0 (1): Unexpected character in %sDateTime_modify_variation1.php on line 99
  93. bool(false)
  94. -- int 12345 --
  95. Warning: DateTime::modify(): Failed to parse time string (12345) at position 4 (5): Unexpected character in %sDateTime_modify_variation1.php on line 99
  96. bool(false)
  97. -- int -12345 --
  98. Warning: DateTime::modify(): Failed to parse time string (-12345) at position 5 (5): Unexpected character in %sDateTime_modify_variation1.php on line 99
  99. bool(false)
  100. -- float 10.5 --
  101. object(DateTime)#3 (3) {
  102. ["date"]=>
  103. string(26) "2009-01-31 10:05:00.000000"
  104. ["timezone_type"]=>
  105. int(3)
  106. ["timezone"]=>
  107. string(13) "Europe/London"
  108. }
  109. -- float -10.5 --
  110. Warning: DateTime::modify(): Failed to parse time string (-10.5) at position 4 (5): Unexpected character in %sDateTime_modify_variation1.php on line 99
  111. bool(false)
  112. -- float .5 --
  113. object(DateTime)#3 (3) {
  114. ["date"]=>
  115. string(26) "2009-01-31 00:05:00.000000"
  116. ["timezone_type"]=>
  117. int(3)
  118. ["timezone"]=>
  119. string(13) "Europe/London"
  120. }
  121. -- empty array --
  122. Warning: DateTime::modify() expects parameter 1 to be string, array given in %sDateTime_modify_variation1.php on line 99
  123. bool(false)
  124. -- int indexed array --
  125. Warning: DateTime::modify() expects parameter 1 to be string, array given in %sDateTime_modify_variation1.php on line 99
  126. bool(false)
  127. -- associative array --
  128. Warning: DateTime::modify() expects parameter 1 to be string, array given in %sDateTime_modify_variation1.php on line 99
  129. bool(false)
  130. -- nested arrays --
  131. Warning: DateTime::modify() expects parameter 1 to be string, array given in %sDateTime_modify_variation1.php on line 99
  132. bool(false)
  133. -- uppercase NULL --
  134. Warning: DateTime::modify(): Failed to parse time string () at position 0 ( in %sDateTime_modify_variation1.php on line 99
  135. bool(false)
  136. -- lowercase null --
  137. Warning: DateTime::modify(): Failed to parse time string () at position 0 ( in %sDateTime_modify_variation1.php on line 99
  138. bool(false)
  139. -- lowercase true --
  140. Warning: DateTime::modify(): Failed to parse time string (1) at position 0 (1): Unexpected character in %sDateTime_modify_variation1.php on line 99
  141. bool(false)
  142. -- lowercase false --
  143. Warning: DateTime::modify(): Failed to parse time string () at position 0 ( in %sDateTime_modify_variation1.php on line 99
  144. bool(false)
  145. -- uppercase TRUE --
  146. Warning: DateTime::modify(): Failed to parse time string (1) at position 0 (1): Unexpected character in %sDateTime_modify_variation1.php on line 99
  147. bool(false)
  148. -- uppercase FALSE --
  149. Warning: DateTime::modify(): Failed to parse time string () at position 0 ( in %sDateTime_modify_variation1.php on line 99
  150. bool(false)
  151. -- empty string DQ --
  152. Warning: DateTime::modify(): Failed to parse time string () at position 0 ( in %sDateTime_modify_variation1.php on line 99
  153. bool(false)
  154. -- empty string SQ --
  155. Warning: DateTime::modify(): Failed to parse time string () at position 0 ( in %sDateTime_modify_variation1.php on line 99
  156. bool(false)
  157. -- string DQ --
  158. Warning: DateTime::modify(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database in %sDateTime_modify_variation1.php on line 99
  159. bool(false)
  160. -- string SQ --
  161. Warning: DateTime::modify(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database in %sDateTime_modify_variation1.php on line 99
  162. bool(false)
  163. -- mixed case string --
  164. Warning: DateTime::modify(): Failed to parse time string (sTrInG) at position 0 (s): The timezone could not be found in the database in %sDateTime_modify_variation1.php on line 99
  165. bool(false)
  166. -- heredoc --
  167. Warning: DateTime::modify(): Failed to parse time string (hello world) at position 0 (h): The timezone could not be found in the database in %sDateTime_modify_variation1.php on line 99
  168. bool(false)
  169. -- instance of classWithToString --
  170. Warning: DateTime::modify(): Failed to parse time string (Class A object) at position 0 (C): The timezone could not be found in the database in %sDateTime_modify_variation1.php on line 99
  171. bool(false)
  172. -- instance of classWithoutToString --
  173. Warning: DateTime::modify() expects parameter 1 to be string, object given in %sDateTime_modify_variation1.php on line 99
  174. bool(false)
  175. -- undefined var --
  176. Warning: DateTime::modify(): Failed to parse time string () at position 0 ( in %sDateTime_modify_variation1.php on line 99
  177. bool(false)
  178. -- unset var --
  179. Warning: DateTime::modify(): Failed to parse time string () at position 0 ( in %sDateTime_modify_variation1.php on line 99
  180. bool(false)
  181. -- resource --
  182. Warning: DateTime::modify() expects parameter 1 to be string, resource given in %sDateTime_modify_variation1.php on line 99
  183. bool(false)
  184. ===DONE===