date_parse_variation1.phpt 4.9 KB

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