1--TEST--
2Test 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
11echo "*** Testing DateTime::__construct() : usage variation -  unexpected values to first argument \$timezone***\n";
12
13//Set the default time zone
14date_default_timezone_set("Europe/London");
15
16//get an unset variable
17$unset_var = 10;
18unset ($unset_var);
19
20// define some classes
21class classWithToString
22{
23	public function __toString() {
24		return "Class A object";
25	}
26}
27
28class classWithoutToString
29{
30}
31
32// heredoc string
33$heredoc = <<<EOT
34hello world
35EOT;
36
37// add arrays
38$index_array = array (1, 2, 3);
39$assoc_array = array ('one' => 1, 'two' => 2);
40
41// resource
42$file_handle = fopen(__FILE__, 'r');
43
44//array of values to iterate over
45$inputs = array(
46
47      // int data
48      'int 0' => 0,
49      'int 1' => 1,
50      'int 12345' => 12345,
51
52      // float data
53      'float 10.5' => 10.5,
54      'float .5' => .5,
55
56      // array data
57      'empty array' => array(),
58      'int indexed array' => $index_array,
59      'associative array' => $assoc_array,
60      'nested arrays' => array('foo', $index_array, $assoc_array),
61
62      // null data
63      'uppercase NULL' => NULL,
64      'lowercase null' => null,
65
66      // boolean data
67      'lowercase true' => true,
68      'lowercase false' =>false,
69      'uppercase TRUE' =>TRUE,
70      'uppercase FALSE' =>FALSE,
71
72      // empty data
73      'empty string DQ' => "",
74      'empty string SQ' => '',
75
76      // string data
77      'string DQ' => "string",
78      'string SQ' => 'string',
79      'mixed case string' => "sTrInG",
80      'heredoc' => $heredoc,
81
82      // object data
83      'instance of classWithToString' => new classWithToString(),
84      'instance of classWithoutToString' => new classWithoutToString(),
85
86      // undefined data
87      'undefined var' => @$undefined_var,
88
89      // unset data
90      'unset var' => @$unset_var,
91
92      // resource
93      'resource' => $file_handle
94);
95
96foreach($inputs as $variation =>$timezone) {
97      echo "\n-- $variation --\n";
98      try {
99      	var_dump( new DateTimezone($timezone) );
100      } catch (Throwable $e) {
101      	  $msg = $e->getMessage();
102      	  echo "FAILED: " . $msg . "\n";
103      }
104
105};
106
107// closing the resource
108fclose( $file_handle );
109
110?>
111===DONE===
112--EXPECT--
113*** Testing DateTime::__construct() : usage variation -  unexpected values to first argument $timezone***
114
115-- int 0 --
116FAILED: DateTimeZone::__construct(): Unknown or bad timezone (0)
117
118-- int 1 --
119FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
120
121-- int 12345 --
122FAILED: DateTimeZone::__construct(): Unknown or bad timezone (12345)
123
124-- float 10.5 --
125FAILED: DateTimeZone::__construct(): Unknown or bad timezone (10.5)
126
127-- float .5 --
128FAILED: DateTimeZone::__construct(): Unknown or bad timezone (0.5)
129
130-- empty array --
131FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
132
133-- int indexed array --
134FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
135
136-- associative array --
137FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
138
139-- nested arrays --
140FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
141
142-- uppercase NULL --
143FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
144
145-- lowercase null --
146FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
147
148-- lowercase true --
149FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
150
151-- lowercase false --
152FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
153
154-- uppercase TRUE --
155FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
156
157-- uppercase FALSE --
158FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
159
160-- empty string DQ --
161FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
162
163-- empty string SQ --
164FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
165
166-- string DQ --
167FAILED: DateTimeZone::__construct(): Unknown or bad timezone (string)
168
169-- string SQ --
170FAILED: DateTimeZone::__construct(): Unknown or bad timezone (string)
171
172-- mixed case string --
173FAILED: DateTimeZone::__construct(): Unknown or bad timezone (sTrInG)
174
175-- heredoc --
176FAILED: DateTimeZone::__construct(): Unknown or bad timezone (hello world)
177
178-- instance of classWithToString --
179FAILED: DateTimeZone::__construct(): Unknown or bad timezone (Class A object)
180
181-- instance of classWithoutToString --
182FAILED: DateTimeZone::__construct() expects parameter 1 to be string, object given
183
184-- undefined var --
185FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
186
187-- unset var --
188FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
189
190-- resource --
191FAILED: DateTimeZone::__construct() expects parameter 1 to be string, resource given
192===DONE===
193