Skip to content

Commit eab553e

Browse files
committed
Add more containers
1 parent 9092858 commit eab553e

File tree

3 files changed

+105
-30
lines changed

3 files changed

+105
-30
lines changed

Zend/tests/offsets/appending_containers.phpt

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@ Appending containers
33
--FILE--
44
<?php
55

6-
$containers = [
7-
null,
8-
false,
9-
true,
10-
10,
11-
25.5,
12-
'string',
13-
[],
14-
new stdClass(),
15-
STDERR,
16-
];
6+
require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';
177

188
foreach ($containers as $container) {
199
try {
@@ -40,9 +30,31 @@ Cannot use a scalar value as an array
4030
Cannot use a scalar value as an array
4131
Cannot use a scalar value as an array
4232
[] operator not supported for strings
33+
[] operator not supported for strings
34+
[] operator not supported for strings
4335
array(1) {
4436
[0]=>
4537
string(5) "value"
4638
}
47-
Cannot use object of type stdClass as array
4839
Cannot use a scalar value as an array
40+
Cannot use object of type stdClass as array
41+
object(ArrayObject)#2 (1) {
42+
["storage":"ArrayObject":private]=>
43+
array(1) {
44+
[0]=>
45+
string(5) "value"
46+
}
47+
}
48+
string(12) "A::offsetSet"
49+
NULL
50+
string(5) "value"
51+
object(A)#3 (0) {
52+
}
53+
string(12) "B::offsetSet"
54+
NULL
55+
string(5) "value"
56+
object(B)#4 (1) {
57+
["storage":"ArrayObject":private]=>
58+
array(0) {
59+
}
60+
}

Zend/tests/offsets/runtime_compile_time_offset_access.phpt

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ opcache.file_update_protection=1
1212

1313
require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';
1414

15-
$containers = [
16-
null,
17-
false,
18-
true,
19-
4,
20-
5.5,
21-
'10',
22-
'25.5',
23-
'string',
24-
[],
25-
STDERR,
26-
new stdClass(),
27-
];
28-
2915
function makeTestFile($container, $offset) {
3016
$offset_p = makeOffset($offset);
3117
$container_p = makeContainer($container);
@@ -110,6 +96,9 @@ foreach ($containers as $container_orig) {
11096

11197
$dimension = $offset;
11298
$container = $container_orig;
99+
if (is_object($container_orig)) {
100+
$container = clone $container_orig;
101+
}
113102
include $var_dim_filename;
114103
$varOutput = ob_get_contents();
115104
ob_clean();
@@ -120,9 +109,9 @@ foreach ($containers as $container_orig) {
120109
);
121110

122111
if ($constOutput !== $varOutput) {
123-
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_const_{$failuresNb}.txt", $constOutput);
124-
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_var_{$failuresNb}.txt", $varOutput);
125-
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_test_case_{$failuresNb}.txt", makeTestFile($container_orig, $offset));
112+
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_const.txt", $constOutput);
113+
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_var.txt", $varOutput);
114+
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_test_case.txt", makeTestFile($container_orig, $offset));
126115
++$failuresNb;
127116
$failures[] = $error;
128117
}
@@ -143,4 +132,4 @@ $fl = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_offsets_temp.php';
143132
@unlink($fl);
144133
?>
145134
--EXPECT--
146-
Executed 231 tests
135+
Executed 294 tests

Zend/tests/offsets/test_offset_helpers.inc

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ function makeContainer($container) {
2222
if ($container instanceof stdClass) {
2323
return "new stdClass()";
2424
}
25+
if ($container instanceof B) {
26+
return "new B()";
27+
}
28+
if ($container instanceof A) {
29+
return "new A()";
30+
}
31+
if ($container instanceof ArrayObject) {
32+
return "new ArrayObject()";
33+
}
2534
return var_export($container, true);
2635
}
2736
function makeOffset($offset) {
@@ -55,6 +64,71 @@ function expectf_to_regex(string $wanted): string
5564
]);
5665
}
5766

67+
class A implements ArrayAccess {
68+
public function offsetSet($offset, $value): void {
69+
var_dump(__METHOD__);
70+
var_dump($offset);
71+
var_dump($value);
72+
}
73+
public function offsetGet($offset): mixed {
74+
var_dump(__METHOD__);
75+
var_dump($offset);
76+
return "dummy";
77+
}
78+
public function offsetUnset($offset): void {
79+
var_dump(__METHOD__);
80+
var_dump($offset);
81+
}
82+
public function offsetExists($offset): bool {
83+
var_dump(__METHOD__);
84+
var_dump($offset);
85+
return false;
86+
}
87+
}
88+
89+
class B extends ArrayObject {
90+
public function offsetSet($offset, $value): void {
91+
var_dump(__METHOD__);
92+
var_dump($offset);
93+
var_dump($value);
94+
}
95+
public function offsetGet($offset): mixed {
96+
var_dump(__METHOD__);
97+
var_dump($offset);
98+
return "dummy";
99+
}
100+
public function offsetUnset($offset): void {
101+
var_dump(__METHOD__);
102+
var_dump($offset);
103+
}
104+
public function offsetExists($offset): bool {
105+
var_dump(__METHOD__);
106+
var_dump($offset);
107+
return false;
108+
}
109+
public function append(mixed $value) : void{
110+
var_dump(__METHOD__);
111+
var_dump($value);
112+
}
113+
}
114+
115+
$containers = [
116+
null,
117+
false,
118+
true,
119+
4,
120+
5.5,
121+
'10',
122+
'25.5',
123+
'string',
124+
[],
125+
STDERR,
126+
new stdClass(),
127+
new ArrayObject(),
128+
new A(),
129+
new B(),
130+
];
131+
58132
$offsets = [
59133
null,
60134
false,

0 commit comments

Comments
 (0)