1--TEST--
2Test timezone_offset_get() function : error conditions
3--FILE--
4<?php
5/* Prototype  : int timezone_offset_get  ( DateTimeZone $object  , DateTime $datetime  )
6 * Description: Returns the timezone offset from GMT
7 * Source code: ext/date/php_date.c
8 * Alias to functions: DateTimeZone::getOffset
9 */
10
11//Set the default time zone
12date_default_timezone_set("GMT");
13$tz = timezone_open("Europe/London");
14$date = date_create("GMT");
15
16set_error_handler('err');
17
18function err($errno, $errstr) {
19	if ($errno === E_RECOVERABLE_ERROR) {
20		var_dump($errstr);
21	}
22}
23
24echo "*** Testing timezone_offset_get() : error conditions ***\n";
25
26echo "\n-- Testing timezone_offset_get() function with zero arguments --\n";
27try {
28	var_dump( timezone_offset_get() );
29} catch (Error $ex) {
30	var_dump($ex->getMessage());
31	echo "\n";
32}
33
34echo "\n-- Testing timezone_offset_get() function with less than expected no. of arguments --\n";
35try {
36	var_dump( timezone_offset_get($tz) );
37} catch (Error $ex) {
38	var_dump($ex->getMessage());
39	echo "\n";
40}
41
42echo "\n-- Testing timezone_offset_get() function with more than expected no. of arguments --\n";
43$extra_arg = 99;
44try {
45	var_dump( timezone_offset_get($tz, $date, $extra_arg) );
46} catch (Error $ex) {
47	var_dump($ex->getMessage());
48	echo "\n";
49}
50
51echo "\n-- Testing timezone_offset_get() function with an invalid values for \$object argument --\n";
52$invalid_obj = new stdClass();
53try {
54	var_dump( timezone_offset_get($invalid_obj, $date) );
55} catch (Error $ex) {
56	var_dump($ex->getMessage());
57	echo "\n";
58}
59$invalid_obj = 10;
60try {
61	var_dump( timezone_offset_get($invalid_obj, $date) );
62} catch (Error $ex) {
63	var_dump($ex->getMessage());
64	echo "\n";
65}
66$invalid_obj = null;
67try {
68	var_dump( timezone_offset_get($invalid_obj, $date) );
69} catch (Error $ex) {
70	var_dump($ex->getMessage());
71	echo "\n";
72}
73
74echo "\n-- Testing timezone_offset_get() function with an invalid values for \$datetime argument --\n";
75$invalid_obj = new stdClass();
76try {
77	var_dump( timezone_offset_get($tz, $invalid_obj) );
78} catch (Error $ex) {
79	var_dump($ex->getMessage());
80	echo "\n";
81}
82$invalid_obj = 10;
83try {
84	var_dump( timezone_offset_get($tz, $invalid_obj) );
85} catch (Error $ex) {
86	var_dump($ex->getMessage());
87	echo "\n";
88}
89$invalid_obj = null;
90try {
91	var_dump( timezone_offset_get($tz, $invalid_obj) );
92} catch (Error $ex) {
93	var_dump($ex->getMessage());
94	echo "\n";
95}
96?>
97===DONE===
98--EXPECTF--
99*** Testing timezone_offset_get() : error conditions ***
100
101-- Testing timezone_offset_get() function with zero arguments --
102bool(false)
103
104-- Testing timezone_offset_get() function with less than expected no. of arguments --
105bool(false)
106
107-- Testing timezone_offset_get() function with more than expected no. of arguments --
108bool(false)
109
110-- Testing timezone_offset_get() function with an invalid values for $object argument --
111string(%d) "Argument 1 passed to timezone_offset_get() must be an instance of DateTimeZone, instance of stdClass given"
112
113string(%d) "Argument 1 passed to timezone_offset_get() must be an instance of DateTimeZone, integer given"
114
115string(%d) "Argument 1 passed to timezone_offset_get() must be an instance of DateTimeZone, null given"
116
117
118-- Testing timezone_offset_get() function with an invalid values for $datetime argument --
119string(%d) "Argument 2 passed to timezone_offset_get() must implement interface DateTimeInterface, instance of stdClass given"
120
121string(%d) "Argument 2 passed to timezone_offset_get() must implement interface DateTimeInterface, integer given"
122
123string(%d) "Argument 2 passed to timezone_offset_get() must implement interface DateTimeInterface, null given"
124
125===DONE===
126