DateTimeZone_construct_variation1.phpt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. --TEST--
  2. Test DateTime::__construct() function : usage variation - Passing unexpected values to first argument $timezone.
  3. --FILE--
  4. <?php
  5. /* Prototype : DateTimeZone::__construct ( string $timezone )
  6. * Description: Returns new DateTimeZone object
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing DateTime::__construct() : usage variation - unexpected values to first argument \$timezone***\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. // float data
  42. 'float 10.5' => 10.5,
  43. 'float .5' => .5,
  44. // array data
  45. 'empty array' => array(),
  46. 'int indexed array' => $index_array,
  47. 'associative array' => $assoc_array,
  48. 'nested arrays' => array('foo', $index_array, $assoc_array),
  49. // null data
  50. 'uppercase NULL' => NULL,
  51. 'lowercase null' => null,
  52. // boolean data
  53. 'lowercase true' => true,
  54. 'lowercase false' =>false,
  55. 'uppercase TRUE' =>TRUE,
  56. 'uppercase FALSE' =>FALSE,
  57. // empty data
  58. 'empty string DQ' => "",
  59. 'empty string SQ' => '',
  60. // string data
  61. 'string DQ' => "string",
  62. 'string SQ' => 'string',
  63. 'mixed case string' => "sTrInG",
  64. 'heredoc' => $heredoc,
  65. // object data
  66. 'instance of classWithToString' => new classWithToString(),
  67. 'instance of classWithoutToString' => new classWithoutToString(),
  68. // undefined data
  69. 'undefined var' => @$undefined_var,
  70. // unset data
  71. 'unset var' => @$unset_var,
  72. // resource
  73. 'resource' => $file_handle
  74. );
  75. foreach($inputs as $variation =>$timezone) {
  76. echo "\n-- $variation --\n";
  77. try {
  78. var_dump( new DateTimezone($timezone) );
  79. } catch(Exception $e) {
  80. $msg = $e->getMessage();
  81. echo "FAILED: " . $msg . "\n";
  82. }
  83. };
  84. // closing the resource
  85. fclose( $file_handle );
  86. ?>
  87. ===DONE===
  88. --EXPECTF--
  89. *** Testing DateTime::__construct() : usage variation - unexpected values to first argument $timezone***
  90. -- int 0 --
  91. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (0)
  92. -- int 1 --
  93. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
  94. -- int 12345 --
  95. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (12345)
  96. -- float 10.5 --
  97. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (10.5)
  98. -- float .5 --
  99. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (0.5)
  100. -- empty array --
  101. FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
  102. -- int indexed array --
  103. FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
  104. -- associative array --
  105. FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
  106. -- nested arrays --
  107. FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
  108. -- uppercase NULL --
  109. FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
  110. -- lowercase null --
  111. FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
  112. -- lowercase true --
  113. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
  114. -- lowercase false --
  115. FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
  116. -- uppercase TRUE --
  117. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
  118. -- uppercase FALSE --
  119. FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
  120. -- empty string DQ --
  121. FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
  122. -- empty string SQ --
  123. FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
  124. -- string DQ --
  125. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (string)
  126. -- string SQ --
  127. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (string)
  128. -- mixed case string --
  129. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (sTrInG)
  130. -- heredoc --
  131. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (hello world)
  132. -- instance of classWithToString --
  133. FAILED: DateTimeZone::__construct(): Unknown or bad timezone (Class A object)
  134. -- instance of classWithoutToString --
  135. FAILED: DateTimeZone::__construct() expects parameter 1 to be string, object given
  136. -- undefined var --
  137. FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
  138. -- unset var --
  139. FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
  140. -- resource --
  141. FAILED: DateTimeZone::__construct() expects parameter 1 to be string, resource given
  142. ===DONE===