Annotation of embedaddon/php/ext/date/tests/date_parse_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test date_parse() function : usage variation - Passing unexpected values to first argument $date.
3: --FILE--
4: <?php
5: /* Prototype : array date_parse ( string $date )
6: * Description: Returns associative array with detailed info about given date.
7: * Source code: ext/date/php_date.c
8: */
9:
10: echo "*** Testing date_parse() : usage variation - unexpected values to first argument \$date***\n";
11:
12: //Set the default time zone
13: date_default_timezone_set("Europe/London");
14:
15: //get an unset variable
16: $unset_var = 10;
17: unset ($unset_var);
18:
19: // define some classes
20: class classWithToString
21: {
22: public function __toString() {
23: return "Class A object";
24: }
25: }
26:
27: class classWithoutToString
28: {
29: }
30:
31: // heredoc string
32: $heredoc = <<<EOT
33: hello world
34: EOT;
35:
36: // add arrays
37: $index_array = array (1, 2, 3);
38: $assoc_array = array ('one' => 1, 'two' => 2);
39:
40: // resource
41: $file_handle = fopen(__FILE__, 'r');
42:
43: //array of values to iterate over
44: $inputs = array(
45:
46: // int data
47: 'int 0' => 0,
48: 'int 1' => 1,
49: 'int 12345' => 12345,
50: 'int -12345' => -12345,
51:
52: // float data
53: 'float 10.5' => 10.5,
54: 'float -10.5' => -10.5,
55: 'float .5' => .5,
56:
57: // array data
58: 'empty array' => array(),
59: 'int indexed array' => $index_array,
60: 'associative array' => $assoc_array,
61: 'nested arrays' => array('foo', $index_array, $assoc_array),
62:
63: // null data
64: 'uppercase NULL' => NULL,
65: 'lowercase null' => null,
66:
67: // boolean data
68: 'lowercase true' => true,
69: 'lowercase false' =>false,
70: 'uppercase TRUE' =>TRUE,
71: 'uppercase FALSE' =>FALSE,
72:
73: // empty data
74: 'empty string DQ' => "",
75: 'empty string SQ' => '',
76:
77: // string data
78: 'string DQ' => "string",
79: 'string SQ' => 'string',
80: 'mixed case string' => "sTrInG",
81: 'heredoc' => $heredoc,
82:
83: // object data
84: 'instance of classWithToString' => new classWithToString(),
85: 'instance of classWithoutToString' => new classWithoutToString(),
86:
87: // undefined data
88: 'undefined var' => @$undefined_var,
89:
90: // unset data
91: 'unset var' => @$unset_var,
92:
93: // resource
94: 'resource' => $file_handle
95: );
96:
97: foreach($inputs as $variation =>$date) {
98: echo "\n-- $variation --\n";
99: $result = date_parse($date);
100: if (is_array($result)) {
101: var_dump($result["errors"]);
102: } else {
103: var_dump($result);
104: }
105: };
106:
107: // closing the resource
108: fclose( $file_handle );
109:
110: ?>
111: ===DONE===
112: --EXPECTF--
113: *** Testing date_parse() : usage variation - unexpected values to first argument $date***
114:
115: -- int 0 --
116: array(1) {
117: [0]=>
118: string(20) "Unexpected character"
119: }
120:
121: -- int 1 --
122: array(1) {
123: [0]=>
124: string(20) "Unexpected character"
125: }
126:
127: -- int 12345 --
128: array(1) {
129: [4]=>
130: string(20) "Unexpected character"
131: }
132:
133: -- int -12345 --
134: array(1) {
135: [5]=>
136: string(20) "Unexpected character"
137: }
138:
139: -- float 10.5 --
140: array(0) {
141: }
142:
143: -- float -10.5 --
144: array(1) {
145: [4]=>
146: string(20) "Unexpected character"
147: }
148:
149: -- float .5 --
150: array(0) {
151: }
152:
153: -- empty array --
154:
155: Warning: date_parse() expects parameter 1 to be string, array given in %s on line %d
156: bool(false)
157:
158: -- int indexed array --
159:
160: Warning: date_parse() expects parameter 1 to be string, array given in %s on line %d
161: bool(false)
162:
163: -- associative array --
164:
165: Warning: date_parse() expects parameter 1 to be string, array given in %s on line %d
166: bool(false)
167:
168: -- nested arrays --
169:
170: Warning: date_parse() expects parameter 1 to be string, array given in %s on line %d
171: bool(false)
172:
173: -- uppercase NULL --
174: array(1) {
175: [0]=>
176: string(12) "Empty string"
177: }
178:
179: -- lowercase null --
180: array(1) {
181: [0]=>
182: string(12) "Empty string"
183: }
184:
185: -- lowercase true --
186: array(1) {
187: [0]=>
188: string(20) "Unexpected character"
189: }
190:
191: -- lowercase false --
192: array(1) {
193: [0]=>
194: string(12) "Empty string"
195: }
196:
197: -- uppercase TRUE --
198: array(1) {
199: [0]=>
200: string(20) "Unexpected character"
201: }
202:
203: -- uppercase FALSE --
204: array(1) {
205: [0]=>
206: string(12) "Empty string"
207: }
208:
209: -- empty string DQ --
210: array(1) {
211: [0]=>
212: string(12) "Empty string"
213: }
214:
215: -- empty string SQ --
216: array(1) {
217: [0]=>
218: string(12) "Empty string"
219: }
220:
221: -- string DQ --
222: array(1) {
223: [0]=>
224: string(47) "The timezone could not be found in the database"
225: }
226:
227: -- string SQ --
228: array(1) {
229: [0]=>
230: string(47) "The timezone could not be found in the database"
231: }
232:
233: -- mixed case string --
234: array(1) {
235: [0]=>
236: string(47) "The timezone could not be found in the database"
237: }
238:
239: -- heredoc --
240: array(1) {
241: [0]=>
242: string(47) "The timezone could not be found in the database"
243: }
244:
245: -- instance of classWithToString --
246: array(2) {
247: [0]=>
248: string(47) "The timezone could not be found in the database"
249: [8]=>
250: string(29) "Double timezone specification"
251: }
252:
253: -- instance of classWithoutToString --
254:
255: Warning: date_parse() expects parameter 1 to be string, object given in %s on line %d
256: bool(false)
257:
258: -- undefined var --
259: array(1) {
260: [0]=>
261: string(12) "Empty string"
262: }
263:
264: -- unset var --
265: array(1) {
266: [0]=>
267: string(12) "Empty string"
268: }
269:
270: -- resource --
271:
272: Warning: date_parse() expects parameter 1 to be string, resource given in %s on line %d
273: bool(false)
274: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>