2009-03-18 23:35:10 +00:00
|
|
|
--TEST--
|
2014-09-20 21:16:39 +00:00
|
|
|
Test timezone_offset_get() function : error conditions
|
2009-03-18 23:35:10 +00:00
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
/* Prototype : int timezone_offset_get ( DateTimeZone $object , DateTime $datetime )
|
|
|
|
* Description: Returns the timezone offset from GMT
|
|
|
|
* Source code: ext/date/php_date.c
|
|
|
|
* Alias to functions: DateTimeZone::getOffset
|
|
|
|
*/
|
2014-09-20 21:16:39 +00:00
|
|
|
|
|
|
|
//Set the default time zone
|
2009-03-18 23:35:10 +00:00
|
|
|
date_default_timezone_set("GMT");
|
|
|
|
$tz = timezone_open("Europe/London");
|
|
|
|
$date = date_create("GMT");
|
2014-09-20 21:16:39 +00:00
|
|
|
|
2009-03-18 23:35:10 +00:00
|
|
|
echo "*** Testing timezone_offset_get() : error conditions ***\n";
|
|
|
|
|
|
|
|
echo "\n-- Testing timezone_offset_get() function with zero arguments --\n";
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get() );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
|
|
|
|
echo "\n-- Testing timezone_offset_get() function with less than expected no. of arguments --\n";
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get($tz) );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
|
|
|
|
echo "\n-- Testing timezone_offset_get() function with more than expected no. of arguments --\n";
|
|
|
|
$extra_arg = 99;
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get($tz, $date, $extra_arg) );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
|
|
|
|
echo "\n-- Testing timezone_offset_get() function with an invalid values for \$object argument --\n";
|
|
|
|
$invalid_obj = new stdClass();
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get($invalid_obj, $date) );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
$invalid_obj = 10;
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get($invalid_obj, $date) );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
$invalid_obj = null;
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get($invalid_obj, $date) );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
|
|
|
|
echo "\n-- Testing timezone_offset_get() function with an invalid values for \$datetime argument --\n";
|
|
|
|
$invalid_obj = new stdClass();
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get($tz, $invalid_obj) );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
$invalid_obj = 10;
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get($tz, $invalid_obj) );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
$invalid_obj = null;
|
2015-03-09 12:57:15 +00:00
|
|
|
try {
|
|
|
|
var_dump( timezone_offset_get($tz, $invalid_obj) );
|
2015-05-16 21:49:14 +00:00
|
|
|
} catch (Error $ex) {
|
2015-03-09 12:57:15 +00:00
|
|
|
var_dump($ex->getMessage());
|
|
|
|
echo "\n";
|
|
|
|
}
|
2009-03-18 23:35:10 +00:00
|
|
|
?>
|
|
|
|
===DONE===
|
|
|
|
--EXPECTF--
|
|
|
|
*** Testing timezone_offset_get() : error conditions ***
|
|
|
|
|
|
|
|
-- Testing timezone_offset_get() function with zero arguments --
|
2018-11-15 20:12:47 +00:00
|
|
|
|
|
|
|
Warning: timezone_offset_get() expects exactly 2 parameters, 0 given in %s on line %d
|
2009-03-18 23:35:10 +00:00
|
|
|
bool(false)
|
|
|
|
|
|
|
|
-- Testing timezone_offset_get() function with less than expected no. of arguments --
|
2018-11-15 20:12:47 +00:00
|
|
|
|
|
|
|
Warning: timezone_offset_get() expects exactly 2 parameters, 1 given in %s on line %d
|
2009-03-18 23:35:10 +00:00
|
|
|
bool(false)
|
|
|
|
|
|
|
|
-- Testing timezone_offset_get() function with more than expected no. of arguments --
|
2018-11-15 20:12:47 +00:00
|
|
|
|
|
|
|
Warning: timezone_offset_get() expects exactly 2 parameters, 3 given in %s on line %d
|
2009-03-18 23:35:10 +00:00
|
|
|
bool(false)
|
|
|
|
|
|
|
|
-- Testing timezone_offset_get() function with an invalid values for $object argument --
|
2014-09-20 21:16:39 +00:00
|
|
|
string(%d) "Argument 1 passed to timezone_offset_get() must be an instance of DateTimeZone, instance of stdClass given"
|
2015-03-09 12:57:15 +00:00
|
|
|
|
2018-02-04 13:33:49 +00:00
|
|
|
string(%d) "Argument 1 passed to timezone_offset_get() must be an instance of DateTimeZone, int given"
|
2015-03-09 12:57:15 +00:00
|
|
|
|
2014-09-20 21:16:39 +00:00
|
|
|
string(%d) "Argument 1 passed to timezone_offset_get() must be an instance of DateTimeZone, null given"
|
2015-03-09 12:57:15 +00:00
|
|
|
|
2009-03-18 23:35:10 +00:00
|
|
|
|
|
|
|
-- Testing timezone_offset_get() function with an invalid values for $datetime argument --
|
2014-09-20 21:16:39 +00:00
|
|
|
string(%d) "Argument 2 passed to timezone_offset_get() must implement interface DateTimeInterface, instance of stdClass given"
|
2015-03-09 12:57:15 +00:00
|
|
|
|
2018-02-04 13:33:49 +00:00
|
|
|
string(%d) "Argument 2 passed to timezone_offset_get() must implement interface DateTimeInterface, int given"
|
2015-03-09 12:57:15 +00:00
|
|
|
|
2014-09-20 21:16:39 +00:00
|
|
|
string(%d) "Argument 2 passed to timezone_offset_get() must implement interface DateTimeInterface, null given"
|
2015-03-09 12:57:15 +00:00
|
|
|
|
2009-03-18 23:35:10 +00:00
|
|
|
===DONE===
|