DateTimeZone_getOffset_variation1.phpt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. --TEST--
  2. Test DateTimeZone::getOffset() function : usage variation - Passing unexpected values to first argument $datetime.
  3. --FILE--
  4. <?php
  5. /* Prototype : int DateTimeZone::getOffset ( DateTime $datetime )
  6. * Description: Returns the timezone offset from GMT
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions: timezone_offset_get()
  9. */
  10. echo "*** Testing DateTimeZone::getOffset() : usage variation - unexpected values to first argument \$datetime***\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. $timezone = new DateTimezone("Europe/London");
  78. foreach($inputs as $variation =>$datetime) {
  79. echo "\n-- $variation --\n";
  80. var_dump( $timezone->getOffset($datetime) );
  81. };
  82. // closing the resource
  83. fclose( $file_handle );
  84. ?>
  85. ===DONE===
  86. --EXPECTF--
  87. *** Testing DateTimeZone::getOffset() : usage variation - unexpected values to first argument $datetime***
  88. -- int 0 --
  89. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, integer given in %s on line %d
  90. bool(false)
  91. -- int 1 --
  92. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, integer given in %s on line %d
  93. bool(false)
  94. -- int 12345 --
  95. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, integer given in %s on line %d
  96. bool(false)
  97. -- int -12345 --
  98. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, integer given in %s on line %d
  99. bool(false)
  100. -- float 10.5 --
  101. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, double given in %s on line %d
  102. bool(false)
  103. -- float -10.5 --
  104. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, double given in %s on line %d
  105. bool(false)
  106. -- float .5 --
  107. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, double given in %s on line %d
  108. bool(false)
  109. -- empty array --
  110. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, array given in %s on line %d
  111. bool(false)
  112. -- int indexed array --
  113. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, array given in %s on line %d
  114. bool(false)
  115. -- associative array --
  116. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, array given in %s on line %d
  117. bool(false)
  118. -- nested arrays --
  119. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, array given in %s on line %d
  120. bool(false)
  121. -- uppercase NULL --
  122. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, null given in %s on line %d
  123. bool(false)
  124. -- lowercase null --
  125. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, null given in %s on line %d
  126. bool(false)
  127. -- lowercase true --
  128. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, boolean given in %s on line %d
  129. bool(false)
  130. -- lowercase false --
  131. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, boolean given in %s on line %d
  132. bool(false)
  133. -- uppercase TRUE --
  134. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, boolean given in %s on line %d
  135. bool(false)
  136. -- uppercase FALSE --
  137. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, boolean given in %s on line %d
  138. bool(false)
  139. -- empty string DQ --
  140. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, string given in %s on line %d
  141. bool(false)
  142. -- empty string SQ --
  143. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, string given in %s on line %d
  144. bool(false)
  145. -- string DQ --
  146. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, string given in %s on line %d
  147. bool(false)
  148. -- string SQ --
  149. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, string given in %s on line %d
  150. bool(false)
  151. -- mixed case string --
  152. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, string given in %s on line %d
  153. bool(false)
  154. -- heredoc --
  155. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, string given in %s on line %d
  156. bool(false)
  157. -- instance of classWithToString --
  158. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, object given in %s on line %d
  159. bool(false)
  160. -- instance of classWithoutToString --
  161. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, object given in %s on line %d
  162. bool(false)
  163. -- undefined var --
  164. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, null given in %s on line %d
  165. bool(false)
  166. -- unset var --
  167. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, null given in %s on line %d
  168. bool(false)
  169. -- resource --
  170. Warning: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, resource given in %s on line %d
  171. bool(false)
  172. ===DONE===