Annotation of embedaddon/php/ext/date/tests/DateTime_format_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test DateTime::format() function : usage variation - Passing unexpected values to first argument $format.
3: --FILE--
4: <?php
5: /* Prototype : public string DateTime::format ( string $format )
6: * Description: Returns date formatted according to given format
7: * Source code: ext/date/php_date.c
8: * Alias to functions: date_format
9: */
10:
11: echo "*** Testing DateTime::format() : usage variation - unexpected values to first argument \$format***\n";
12:
13: //Set the default time zone
14: date_default_timezone_set("Europe/London");
15:
16: //get an unset variable
17: $unset_var = 10;
18: unset ($unset_var);
19:
20: // define some classes
21: class classWithToString
22: {
23: public function __toString() {
24: return "Class A object";
25: }
26: }
27:
28: class classWithoutToString
29: {
30: }
31:
32: // heredoc string
33: $heredoc = <<<EOT
34: hello world
35: EOT;
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: 'int -12345' => -12345,
52:
53: // float data
54: 'float 10.5' => 10.5,
55: 'float -10.5' => -10.5,
56: 'float .5' => .5,
57:
58: // array data
59: 'empty array' => array(),
60: 'int indexed array' => $index_array,
61: 'associative array' => $assoc_array,
62: 'nested arrays' => array('foo', $index_array, $assoc_array),
63:
64: // null data
65: 'uppercase NULL' => NULL,
66: 'lowercase null' => null,
67:
68: // boolean data
69: 'lowercase true' => true,
70: 'lowercase false' =>false,
71: 'uppercase TRUE' =>TRUE,
72: 'uppercase FALSE' =>FALSE,
73:
74: // empty data
75: 'empty string DQ' => "",
76: 'empty string SQ' => '',
77:
78: // string data
79: 'string DQ' => "string",
80: 'string SQ' => 'string',
81: 'mixed case string' => "sTrInG",
82: 'heredoc' => $heredoc,
83:
84: // object data
85: 'instance of classWithToString' => new classWithToString(),
86: 'instance of classWithoutToString' => new classWithoutToString(),
87:
88: // undefined data
89: 'undefined var' => @$undefined_var,
90:
91: // unset data
92: 'unset var' => @$unset_var,
93:
94: // resource
95: 'resource' => $file_handle
96: );
97:
98: $object = new DateTime("2005-07-14 22:30:41");
99:
100: foreach($inputs as $variation =>$format) {
101: echo "\n-- $variation --\n";
102: var_dump( $object->format($format) );
103: };
104:
105: // closing the resource
106: fclose( $file_handle );
107:
108: ?>
109: ===DONE===
110: --EXPECTF--
111: *** Testing DateTime::format() : usage variation - unexpected values to first argument $format***
112:
113: -- int 0 --
114: string(1) "0"
115:
116: -- int 1 --
117: string(1) "1"
118:
119: -- int 12345 --
120: string(5) "12345"
121:
122: -- int -12345 --
123: string(6) "-12345"
124:
125: -- float 10.5 --
126: string(4) "10.5"
127:
128: -- float -10.5 --
129: string(5) "-10.5"
130:
131: -- float .5 --
132: string(3) "0.5"
133:
134: -- empty array --
135:
136: Warning: DateTime::format() expects parameter 1 to be string, array given in %s on line %d
137: bool(false)
138:
139: -- int indexed array --
140:
141: Warning: DateTime::format() expects parameter 1 to be string, array given in %s on line %d
142: bool(false)
143:
144: -- associative array --
145:
146: Warning: DateTime::format() expects parameter 1 to be string, array given in %s on line %d
147: bool(false)
148:
149: -- nested arrays --
150:
151: Warning: DateTime::format() expects parameter 1 to be string, array given in %s on line %d
152: bool(false)
153:
154: -- uppercase NULL --
155: string(0) ""
156:
157: -- lowercase null --
158: string(0) ""
159:
160: -- lowercase true --
161: string(1) "1"
162:
163: -- lowercase false --
164: string(0) ""
165:
166: -- uppercase TRUE --
167: string(1) "1"
168:
169: -- uppercase FALSE --
170: string(0) ""
171:
172: -- empty string DQ --
173: string(0) ""
174:
175: -- empty string SQ --
176: string(0) ""
177:
178: -- string DQ --
179: string(40) "4131Thu, 14 Jul 2005 22:30:41 +010030710"
180:
181: -- string SQ --
182: string(40) "4131Thu, 14 Jul 2005 22:30:41 +010030710"
183:
184: -- mixed case string --
185: string(40) "41BSTThu, 14 Jul 2005 22:30:41 +01001722"
186:
187: -- heredoc --
188: string(82) "10Europe/LondonThursdayThursday2005 42005Thu, 14 Jul 2005 22:30:41 +0100Thursday14"
189:
190: -- instance of classWithToString --
191: string(66) "CThursdaypm4141 PM 2005b14Europe/London2005-07-14T22:30:41+01:0031"
192:
193: -- instance of classWithoutToString --
194:
195: Warning: DateTime::format() expects parameter 1 to be string, object given in %s on line %d
196: bool(false)
197:
198: -- undefined var --
199: string(0) ""
200:
201: -- unset var --
202: string(0) ""
203:
204: -- resource --
205:
206: Warning: DateTime::format() expects parameter 1 to be string, resource given in %s on line %d
207: bool(false)
208: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>