Skip to content

Commit b12bdf2

Browse files
committed
Add container test for ArrayObject
1 parent 0ebbd7d commit b12bdf2

File tree

1 file changed

+314
-0
lines changed

1 file changed

+314
-0
lines changed
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
--TEST--
2+
ArrayObject containers behaviour with offsets
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';
7+
8+
const EXPECTED_OUTPUT_VALID_OFFSETS = <<<OUTPUT
9+
Read before write:
10+
11+
Warning: Undefined array key %s in %s on line 8
12+
NULL
13+
Write:
14+
Read:
15+
int(5)
16+
Read-Write:
17+
isset():
18+
bool(true)
19+
empty():
20+
bool(false)
21+
null coalesce:
22+
int(25)
23+
unset():
24+
Nested read:
25+
26+
Warning: Undefined array key %s in %s on line 62
27+
28+
Warning: Trying to access array offset on null in %s on line 62
29+
NULL
30+
Nested write:
31+
Nested Read-Write:
32+
Nested isset():
33+
bool(true)
34+
Nested empty():
35+
bool(false)
36+
Nested null coalesce:
37+
int(30)
38+
Nested unset():
39+
OUTPUT;
40+
41+
$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s';
42+
43+
const EXPECTF_OUTPUT_FLOAT_OFFSETS = <<<OUTPUT
44+
Read before write:
45+
46+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 8
47+
48+
Warning: Undefined array key %s in %s on line 8
49+
NULL
50+
Write:
51+
52+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 15
53+
Read:
54+
55+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 22
56+
int(15)
57+
Read-Write:
58+
59+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 29
60+
isset():
61+
62+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 36
63+
bool(true)
64+
empty():
65+
66+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 42
67+
bool(false)
68+
null coalesce:
69+
70+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 48
71+
int(35)
72+
unset():
73+
74+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 55
75+
Nested read:
76+
77+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 62
78+
79+
Warning: Undefined array key 0 in %s on line 62
80+
81+
Warning: Trying to access array offset on null in %s on line 62
82+
NULL
83+
Nested write:
84+
85+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 69
86+
87+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 69
88+
Nested Read-Write:
89+
90+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 76
91+
92+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 76
93+
Nested isset():
94+
95+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 83
96+
97+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 83
98+
bool(true)
99+
Nested empty():
100+
101+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 89
102+
103+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 89
104+
bool(false)
105+
Nested null coalesce:
106+
107+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 95
108+
109+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 95
110+
int(25)
111+
Nested unset():
112+
113+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 102
114+
115+
Deprecated: Implicit conversion from float %F to int loses precision in %s on line 102
116+
117+
OUTPUT;
118+
119+
$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s';
120+
121+
const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT
122+
Read before write:
123+
Cannot access offset of type %s on ArrayObject
124+
Write:
125+
Cannot access offset of type %s on ArrayObject
126+
Read:
127+
Cannot access offset of type %s on ArrayObject
128+
Read-Write:
129+
Cannot access offset of type %s on ArrayObject
130+
isset():
131+
Cannot access offset of type %s in isset or empty
132+
empty():
133+
Cannot access offset of type %s in isset or empty
134+
null coalesce:
135+
Cannot access offset of type %s in isset or empty
136+
unset():
137+
Cannot unset offset of type %s on ArrayObject
138+
Nested read:
139+
Cannot access offset of type %s on ArrayObject
140+
Nested write:
141+
Cannot access offset of type %s on ArrayObject
142+
Nested Read-Write:
143+
Cannot access offset of type %s on ArrayObject
144+
Nested isset():
145+
Cannot access offset of type %s in isset or empty
146+
Nested empty():
147+
Cannot access offset of type %s in isset or empty
148+
Nested null coalesce:
149+
Cannot access offset of type %s in isset or empty
150+
Nested unset():
151+
152+
Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line 102
153+
Cannot unset offset of type %s on ArrayObject
154+
155+
OUTPUT;
156+
157+
$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s';
158+
159+
const EXPECTED_OUTPUT_NULL_OFFSET = <<<OUTPUT
160+
Read before write:
161+
162+
Warning: Undefined array key "" in %s on line 8
163+
NULL
164+
Write:
165+
Read:
166+
167+
Warning: Undefined array key "" in %s on line 22
168+
NULL
169+
Read-Write:
170+
171+
Warning: Undefined array key "" in %s on line 29
172+
isset():
173+
bool(false)
174+
empty():
175+
bool(true)
176+
null coalesce:
177+
string(7) "default"
178+
unset():
179+
Nested read:
180+
181+
Warning: Undefined array key "" in %s on line 62
182+
183+
Warning: Trying to access array offset on null in %s on line 62
184+
NULL
185+
Nested write:
186+
Nested Read-Write:
187+
Nested isset():
188+
bool(true)
189+
Nested empty():
190+
bool(false)
191+
Nested null coalesce:
192+
int(30)
193+
Nested unset():
194+
195+
OUTPUT;
196+
197+
const EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS = <<<OUTPUT
198+
Read before write:
199+
200+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 8
201+
202+
Warning: Undefined array key 3 in %s on line 8
203+
NULL
204+
Write:
205+
206+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 15
207+
Read:
208+
209+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 22
210+
int(5)
211+
Read-Write:
212+
213+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29
214+
215+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29
216+
isset():
217+
218+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 36
219+
bool(true)
220+
empty():
221+
222+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 42
223+
bool(false)
224+
null coalesce:
225+
226+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 48
227+
int(25)
228+
unset():
229+
230+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 55
231+
Nested read:
232+
233+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 62
234+
235+
Warning: Undefined array key 3 in %s on line 62
236+
237+
Warning: Trying to access array offset on null in %s on line 62
238+
NULL
239+
Nested write:
240+
241+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 69
242+
243+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 69
244+
Nested Read-Write:
245+
246+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 76
247+
248+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 76
249+
Nested isset():
250+
251+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 83
252+
253+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 83
254+
bool(true)
255+
Nested empty():
256+
257+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 89
258+
259+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 89
260+
bool(false)
261+
Nested null coalesce:
262+
263+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
264+
265+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
266+
int(30)
267+
Nested unset():
268+
269+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 102
270+
271+
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 102
272+
273+
OUTPUT;
274+
275+
ob_start();
276+
foreach ($offsets as $dimension) {
277+
$container = new ArrayObject();
278+
$error = '(new ArrayObject())[' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
279+
ob_start();
280+
var_dump($dimension);
281+
$var_dump_output = ob_get_clean();
282+
283+
include $var_dim_filename;
284+
$varOutput = ob_get_contents();
285+
ob_clean();
286+
$varOutput = str_replace(
287+
[$var_dim_filename],
288+
['%s'],
289+
$varOutput
290+
);
291+
292+
if (
293+
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
294+
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
295+
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
296+
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
297+
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
298+
) {
299+
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayObject_container_{$failuresNb}.txt", $varOutput);
300+
++$failuresNb;
301+
$failures[] = $error;
302+
}
303+
++$testCasesTotal;
304+
}
305+
ob_end_clean();
306+
307+
echo "Executed tests\n";
308+
if ($failures !== []) {
309+
echo "Failures:\n" . implode($failures);
310+
}
311+
312+
?>
313+
--EXPECT--
314+
Executed tests

0 commit comments

Comments
 (0)