Annotation of embedaddon/php/ext/date/tests/date_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test date() function : usage variation - Passing unexpected values to second argument $timestamp.
3: --FILE--
4: <?php
5: /* Prototype : string date ( string $format [, int $timestamp ] )
6: * Description: Format a local time/date.
7: * Source code: ext/date/php_date.c
8: */
9:
10: echo "*** Testing date() : usage variation - unexpected values to second argument \$timestamp***\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: $format = "F j, Y, g:i a";
98:
99: foreach($inputs as $variation =>$timestamp) {
100: echo "\n-- $variation --\n";
101: var_dump( date($format, $timestamp) );
102: };
103:
104: // closing the resource
105: fclose( $file_handle );
106:
107: ?>
108: ===DONE===
109: --EXPECTF--
110: *** Testing date() : usage variation - unexpected values to second argument $timestamp***
111:
112: -- int 0 --
113: string(24) "January 1, 1970, 1:00 am"
114:
115: -- int 1 --
116: string(24) "January 1, 1970, 1:00 am"
117:
118: -- int 12345 --
119: string(24) "January 1, 1970, 4:25 am"
120:
121: -- int -12345 --
122: string(26) "December 31, 1969, 9:34 pm"
123:
124: -- float 10.5 --
125: string(24) "January 1, 1970, 1:00 am"
126:
127: -- float -10.5 --
128: string(25) "January 1, 1970, 12:59 am"
129:
130: -- float .5 --
131: string(24) "January 1, 1970, 1:00 am"
132:
133: -- empty array --
134:
135: Warning: date() expects parameter 2 to be long, array given in %s on line %d
136: bool(false)
137:
138: -- int indexed array --
139:
140: Warning: date() expects parameter 2 to be long, array given in %s on line %d
141: bool(false)
142:
143: -- associative array --
144:
145: Warning: date() expects parameter 2 to be long, array given in %s on line %d
146: bool(false)
147:
148: -- nested arrays --
149:
150: Warning: date() expects parameter 2 to be long, array given in %s on line %d
151: bool(false)
152:
153: -- uppercase NULL --
154: string(24) "January 1, 1970, 1:00 am"
155:
156: -- lowercase null --
157: string(24) "January 1, 1970, 1:00 am"
158:
159: -- lowercase true --
160: string(24) "January 1, 1970, 1:00 am"
161:
162: -- lowercase false --
163: string(24) "January 1, 1970, 1:00 am"
164:
165: -- uppercase TRUE --
166: string(24) "January 1, 1970, 1:00 am"
167:
168: -- uppercase FALSE --
169: string(24) "January 1, 1970, 1:00 am"
170:
171: -- empty string DQ --
172:
173: Warning: date() expects parameter 2 to be long, string given in %s on line %d
174: bool(false)
175:
176: -- empty string SQ --
177:
178: Warning: date() expects parameter 2 to be long, string given in %s on line %d
179: bool(false)
180:
181: -- string DQ --
182:
183: Warning: date() expects parameter 2 to be long, string given in %s on line %d
184: bool(false)
185:
186: -- string SQ --
187:
188: Warning: date() expects parameter 2 to be long, string given in %s on line %d
189: bool(false)
190:
191: -- mixed case string --
192:
193: Warning: date() expects parameter 2 to be long, string given in %s on line %d
194: bool(false)
195:
196: -- heredoc --
197:
198: Warning: date() expects parameter 2 to be long, string given in %s on line %d
199: bool(false)
200:
201: -- instance of classWithToString --
202:
203: Warning: date() expects parameter 2 to be long, object given in %s on line %d
204: bool(false)
205:
206: -- instance of classWithoutToString --
207:
208: Warning: date() expects parameter 2 to be long, object given in %s on line %d
209: bool(false)
210:
211: -- undefined var --
212: string(24) "January 1, 1970, 1:00 am"
213:
214: -- unset var --
215: string(24) "January 1, 1970, 1:00 am"
216:
217: -- resource --
218:
219: Warning: date() expects parameter 2 to be long, resource given in %s on line %d
220: bool(false)
221: ===DONE===
222:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>