Annotation of embedaddon/php/ext/standard/tests/array/array_change_key_case_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_change_key_case() function : usage variations - Pass different data types as $case arg
3: --FILE--
4: <?php
5: /* Prototype : array array_change_key_case(array $input [, int $case])
6: * Description: Retuns an array with all string keys lowercased [or uppercased]
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * Pass different data types as $case argument to array_change_key_case() to test behaviour
12: * Where possible, CASE_UPPER has been entered as a string value
13: */
14:
15: echo "*** Testing array_change_key_case() : usage variations ***\n";
16:
17: // Initialise function arguments not being substituted
18: $array = array ('one' => 1, 'TWO' => 2, 'Three' => 3);
19:
20: //get an unset variable
21: $unset_var = 10;
22: unset ($unset_var);
23:
24: // heredoc string
25: $heredoc = <<<EOT
26: CASE_UPPER
27: EOT;
28:
29: // get a resource variable
30: $fp = fopen(__FILE__, "r");
31:
32: // unexpected values to be passed to $case argument
33: $inputs = array(
34:
35: // int data
36: /*1*/ 0,
37: 1,
38: 12345,
39: -2345,
40:
41: // float data
42: /*5*/ 10.5,
43: -10.5,
44: 12.3456789000e10,
45: 12.3456789000E-10,
46: .5,
47:
48: // null data
49: /*10*/ NULL,
50: null,
51:
52: // boolean data
53: /*12*/ true,
54: false,
55: TRUE,
56: FALSE,
57:
58: // empty data
59: /*16*/ "",
60: '',
61: array(),
62:
63: // string data
64: /*19*/ "CASE_UPPER",
65: 'CASE_UPPER',
66: $heredoc,
67:
68: // undefined data
69: /*22*/ @$undefined_var,
70:
71: // unset data
72: /*23*/ @$unset_var,
73: );
74:
75: // loop through each element of $inputs to check the behavior of array_change_key_case()
76: $iterator = 1;
77: foreach($inputs as $input) {
78: echo "\n-- Iteration $iterator --\n";
79: var_dump( array_change_key_case($array, $input) );
80: $iterator++;
81: };
82:
83: echo "Done";
84: ?>
85:
86: --EXPECTF--
87: *** Testing array_change_key_case() : usage variations ***
88:
89: -- Iteration 1 --
90: array(3) {
91: ["one"]=>
92: int(1)
93: ["two"]=>
94: int(2)
95: ["three"]=>
96: int(3)
97: }
98:
99: -- Iteration 2 --
100: array(3) {
101: ["ONE"]=>
102: int(1)
103: ["TWO"]=>
104: int(2)
105: ["THREE"]=>
106: int(3)
107: }
108:
109: -- Iteration 3 --
110: array(3) {
111: ["ONE"]=>
112: int(1)
113: ["TWO"]=>
114: int(2)
115: ["THREE"]=>
116: int(3)
117: }
118:
119: -- Iteration 4 --
120: array(3) {
121: ["ONE"]=>
122: int(1)
123: ["TWO"]=>
124: int(2)
125: ["THREE"]=>
126: int(3)
127: }
128:
129: -- Iteration 5 --
130: array(3) {
131: ["ONE"]=>
132: int(1)
133: ["TWO"]=>
134: int(2)
135: ["THREE"]=>
136: int(3)
137: }
138:
139: -- Iteration 6 --
140: array(3) {
141: ["ONE"]=>
142: int(1)
143: ["TWO"]=>
144: int(2)
145: ["THREE"]=>
146: int(3)
147: }
148:
149: -- Iteration 7 --
150: array(3) {
151: ["ONE"]=>
152: int(1)
153: ["TWO"]=>
154: int(2)
155: ["THREE"]=>
156: int(3)
157: }
158:
159: -- Iteration 8 --
160: array(3) {
161: ["one"]=>
162: int(1)
163: ["two"]=>
164: int(2)
165: ["three"]=>
166: int(3)
167: }
168:
169: -- Iteration 9 --
170: array(3) {
171: ["one"]=>
172: int(1)
173: ["two"]=>
174: int(2)
175: ["three"]=>
176: int(3)
177: }
178:
179: -- Iteration 10 --
180: array(3) {
181: ["one"]=>
182: int(1)
183: ["two"]=>
184: int(2)
185: ["three"]=>
186: int(3)
187: }
188:
189: -- Iteration 11 --
190: array(3) {
191: ["one"]=>
192: int(1)
193: ["two"]=>
194: int(2)
195: ["three"]=>
196: int(3)
197: }
198:
199: -- Iteration 12 --
200: array(3) {
201: ["ONE"]=>
202: int(1)
203: ["TWO"]=>
204: int(2)
205: ["THREE"]=>
206: int(3)
207: }
208:
209: -- Iteration 13 --
210: array(3) {
211: ["one"]=>
212: int(1)
213: ["two"]=>
214: int(2)
215: ["three"]=>
216: int(3)
217: }
218:
219: -- Iteration 14 --
220: array(3) {
221: ["ONE"]=>
222: int(1)
223: ["TWO"]=>
224: int(2)
225: ["THREE"]=>
226: int(3)
227: }
228:
229: -- Iteration 15 --
230: array(3) {
231: ["one"]=>
232: int(1)
233: ["two"]=>
234: int(2)
235: ["three"]=>
236: int(3)
237: }
238:
239: -- Iteration 16 --
240:
241: Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d
242: NULL
243:
244: -- Iteration 17 --
245:
246: Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d
247: NULL
248:
249: -- Iteration 18 --
250:
251: Warning: array_change_key_case() expects parameter 2 to be long, array given in %s on line %d
252: NULL
253:
254: -- Iteration 19 --
255:
256: Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d
257: NULL
258:
259: -- Iteration 20 --
260:
261: Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d
262: NULL
263:
264: -- Iteration 21 --
265:
266: Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d
267: NULL
268:
269: -- Iteration 22 --
270: array(3) {
271: ["one"]=>
272: int(1)
273: ["two"]=>
274: int(2)
275: ["three"]=>
276: int(3)
277: }
278:
279: -- Iteration 23 --
280: array(3) {
281: ["one"]=>
282: int(1)
283: ["two"]=>
284: int(2)
285: ["three"]=>
286: int(3)
287: }
288: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>