date_date_set_variation3.phpt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. --TEST--
  2. Test date_date_set() function : usage variation - Passing unexpected values to third argument $month.
  3. --FILE--
  4. <?php
  5. /* Prototype : DateTime date_date_set ( DateTime $object , int $year , int $month , int $day )
  6. * Description: Resets the current date of the DateTime object to a different date.
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions: DateTime::setDate
  9. */
  10. echo "*** Testing date_date_set() : usage variation - unexpected values to third argument \$month***\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 = date_create("2009-02-27 08:34:10");
  78. $day = 2;
  79. $year = 1963;
  80. foreach($inputs as $variation =>$month) {
  81. echo "\n-- $variation --\n";
  82. var_dump( date_date_set($object, $year, $month, $day) );
  83. };
  84. // closing the resource
  85. fclose( $file_handle );
  86. ?>
  87. ===DONE===
  88. --EXPECTF--
  89. *** Testing date_date_set() : usage variation - unexpected values to third argument $month***
  90. -- int 0 --
  91. object(DateTime)#%d (3) {
  92. ["date"]=>
  93. string(26) "1962-12-02 08:34:10.000000"
  94. ["timezone_type"]=>
  95. int(3)
  96. ["timezone"]=>
  97. string(13) "Europe/London"
  98. }
  99. -- int 1 --
  100. object(DateTime)#%d (3) {
  101. ["date"]=>
  102. string(26) "1963-01-02 08:34:10.000000"
  103. ["timezone_type"]=>
  104. int(3)
  105. ["timezone"]=>
  106. string(13) "Europe/London"
  107. }
  108. -- int 12345 --
  109. object(DateTime)#%d (3) {
  110. ["date"]=>
  111. string(26) "2991-09-02 08:34:10.000000"
  112. ["timezone_type"]=>
  113. int(3)
  114. ["timezone"]=>
  115. string(13) "Europe/London"
  116. }
  117. -- int -12345 --
  118. object(DateTime)#%d (3) {
  119. ["date"]=>
  120. string(26) "0934-03-02 08:34:10.000000"
  121. ["timezone_type"]=>
  122. int(3)
  123. ["timezone"]=>
  124. string(13) "Europe/London"
  125. }
  126. -- float 10.5 --
  127. object(DateTime)#%d (3) {
  128. ["date"]=>
  129. string(26) "1963-10-02 08:34:10.000000"
  130. ["timezone_type"]=>
  131. int(3)
  132. ["timezone"]=>
  133. string(13) "Europe/London"
  134. }
  135. -- float -10.5 --
  136. object(DateTime)#%d (3) {
  137. ["date"]=>
  138. string(26) "1962-02-02 08:34:10.000000"
  139. ["timezone_type"]=>
  140. int(3)
  141. ["timezone"]=>
  142. string(13) "Europe/London"
  143. }
  144. -- float .5 --
  145. object(DateTime)#%d (3) {
  146. ["date"]=>
  147. string(26) "1962-12-02 08:34:10.000000"
  148. ["timezone_type"]=>
  149. int(3)
  150. ["timezone"]=>
  151. string(13) "Europe/London"
  152. }
  153. -- empty array --
  154. Warning: date_date_set() expects parameter 3 to be long, array given in %s on line %d
  155. bool(false)
  156. -- int indexed array --
  157. Warning: date_date_set() expects parameter 3 to be long, array given in %s on line %d
  158. bool(false)
  159. -- associative array --
  160. Warning: date_date_set() expects parameter 3 to be long, array given in %s on line %d
  161. bool(false)
  162. -- nested arrays --
  163. Warning: date_date_set() expects parameter 3 to be long, array given in %s on line %d
  164. bool(false)
  165. -- uppercase NULL --
  166. object(DateTime)#%d (3) {
  167. ["date"]=>
  168. string(26) "1962-12-02 08:34:10.000000"
  169. ["timezone_type"]=>
  170. int(3)
  171. ["timezone"]=>
  172. string(13) "Europe/London"
  173. }
  174. -- lowercase null --
  175. object(DateTime)#%d (3) {
  176. ["date"]=>
  177. string(26) "1962-12-02 08:34:10.000000"
  178. ["timezone_type"]=>
  179. int(3)
  180. ["timezone"]=>
  181. string(13) "Europe/London"
  182. }
  183. -- lowercase true --
  184. object(DateTime)#%d (3) {
  185. ["date"]=>
  186. string(26) "1963-01-02 08:34:10.000000"
  187. ["timezone_type"]=>
  188. int(3)
  189. ["timezone"]=>
  190. string(13) "Europe/London"
  191. }
  192. -- lowercase false --
  193. object(DateTime)#%d (3) {
  194. ["date"]=>
  195. string(26) "1962-12-02 08:34:10.000000"
  196. ["timezone_type"]=>
  197. int(3)
  198. ["timezone"]=>
  199. string(13) "Europe/London"
  200. }
  201. -- uppercase TRUE --
  202. object(DateTime)#%d (3) {
  203. ["date"]=>
  204. string(26) "1963-01-02 08:34:10.000000"
  205. ["timezone_type"]=>
  206. int(3)
  207. ["timezone"]=>
  208. string(13) "Europe/London"
  209. }
  210. -- uppercase FALSE --
  211. object(DateTime)#%d (3) {
  212. ["date"]=>
  213. string(26) "1962-12-02 08:34:10.000000"
  214. ["timezone_type"]=>
  215. int(3)
  216. ["timezone"]=>
  217. string(13) "Europe/London"
  218. }
  219. -- empty string DQ --
  220. Warning: date_date_set() expects parameter 3 to be long, string given in %s on line %d
  221. bool(false)
  222. -- empty string SQ --
  223. Warning: date_date_set() expects parameter 3 to be long, string given in %s on line %d
  224. bool(false)
  225. -- string DQ --
  226. Warning: date_date_set() expects parameter 3 to be long, string given in %s on line %d
  227. bool(false)
  228. -- string SQ --
  229. Warning: date_date_set() expects parameter 3 to be long, string given in %s on line %d
  230. bool(false)
  231. -- mixed case string --
  232. Warning: date_date_set() expects parameter 3 to be long, string given in %s on line %d
  233. bool(false)
  234. -- heredoc --
  235. Warning: date_date_set() expects parameter 3 to be long, string given in %s on line %d
  236. bool(false)
  237. -- instance of classWithToString --
  238. Warning: date_date_set() expects parameter 3 to be long, object given in %s on line %d
  239. bool(false)
  240. -- instance of classWithoutToString --
  241. Warning: date_date_set() expects parameter 3 to be long, object given in %s on line %d
  242. bool(false)
  243. -- undefined var --
  244. object(DateTime)#%d (3) {
  245. ["date"]=>
  246. string(26) "1962-12-02 08:34:10.000000"
  247. ["timezone_type"]=>
  248. int(3)
  249. ["timezone"]=>
  250. string(13) "Europe/London"
  251. }
  252. -- unset var --
  253. object(DateTime)#%d (3) {
  254. ["date"]=>
  255. string(26) "1962-12-02 08:34:10.000000"
  256. ["timezone_type"]=>
  257. int(3)
  258. ["timezone"]=>
  259. string(13) "Europe/London"
  260. }
  261. -- resource --
  262. Warning: date_date_set() expects parameter 3 to be long, resource given in %s on line %d
  263. bool(false)
  264. ===DONE===