8000 [VarDumper] Fix dumping `ArrayObject` with `DumpDataCollector` · symfony/symfony@1058e35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1058e35

Browse files
committed
[VarDumper] Fix dumping ArrayObject with DumpDataCollector
1 parent 1f2c6f7 commit 1058e35

File tree

7 files changed

+41
-61
lines changed

7 files changed

+41
-61
lines changed

src/Symfony/Component/VarDumper/Caster/SplCaster.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ private static function castSplArray($c, array $a, Stub $stub, bool $isNested):
229229
$a = Caster::castObject($c, \get_class($c), method_exists($c, '__debugInfo'), $stub->class);
230230
$c->setFlags($flags);
231231
}
232-
if (\PHP_VERSION_ID < 70400) {
233-
$a[$prefix.'storage'] = $c->getArrayCopy();
234-
}
232+
233+
unset($a["\0ArrayObject\0storage"], $a["\0ArrayIterator\0storage"]);
234+
235235
$a += [
236+
$prefix.'storage' => $c->getArrayCopy(),
236237
8000 $prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
237238
$prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
238239
];

src/Symfony/Component/VarDumper/Dumper/ContextProvider/SourceContextProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getContext(): ?array
4444

4545
$file = $trace[1]['file'];
4646
$line = $trace[1]['line'];
47-
$name = false;
47+
$name = 'Standard input code' === $file ? $file : false;
4848
$fileExcerpt = false;
4949

5050
for ($i = 2; $i < $this->limit; ++$i) {

src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,14 @@ class([123]) extends \ArrayObject {};
174174
$expected = <<<EOTXT
175175
ArrayObject@anonymous {
176176
+"foo": 234
177-
-storage: array:1 [
177+
storage: array:1 [
178178
0 => 123
179179
]
180180
flag::STD_PROP_LIST: false
181181
flag::ARRAY_AS_PROPS: false
182182
iteratorClass: "ArrayIterator"
183183
}
184184
EOTXT;
185-
if (\PHP_VERSION_ID < 70400) {
186-
$expected = str_replace('-storage:', 'storage:', $expected);
187-
}
188185
$this->assertDumpEquals($expected, $var);
189186
}
190187

@@ -195,16 +192,13 @@ public function testArrayIterator()
195192
$expected = <<<EOTXT
196193
Symfony\Component\VarDumper\Tests\Caster\MyArrayIterator {
197194
-foo: 123
198-
-storage: array:1 [
195+
storage: array:1 [
199196
0 => 234
200197
]
201198
flag::STD_PROP_LIST: false
202199
flag::ARRAY_AS_PROPS: false
203200
}
204201
EOTXT;
205-
if (\PHP_VERSION_ID < 70400) {
206-
$expected = str_replace('-storage:', 'storage:', $expected);
207-
}
208202
$this->assertDumpEquals($expected, $var);
209203
}
210204

src/Symfony/Component/VarDumper/Tests/Integration/dump_data_collector.phpt renamed to src/Symfony/Component/VarDumper/Tests/Dumper/functions/dump_data_collector_with_spl_array.phpt

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ putenv('NO_COLOR=1');
66

77
$vendor = __DIR__;
88
while (!file_exists($vendor.'/vendor')) {
9-
$vendor = \dirname($vendor);
9+
$vendor = dirname($vendor);
1010
}
1111
require $vendor.'/vendor/autoload.php';
1212

1313
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
1414
use Symfony\Component\VarDumper\Cloner\VarCloner;
15-
use Symfony\Component\VarDumper\Dumper\CliDumper;
1615
use Symfony\Component\VarDumper\VarDumper;
1716

1817
VarDumper::setHandler(function ($var, string $label = null) {
@@ -30,14 +29,41 @@ VarDumper::setHandler(function ($var, string $label = null) {
3029
$handler($var, $label);
3130
});
3231

33-
$schemas = new \ArrayObject();
34-
dump($schemas);
35-
$schemas['X'] = new \ArrayObject(['type' => 'object']);
32+
$arrayObject = new \ArrayObject();
33+
dump($arrayObject);
34+
$arrayObject['X'] = 'A';
35+
$arrayObject['Y'] = new \ArrayObject(['type' => 'object']);
36+
$arrayObject['Y']['Z'] = 'B';
37+
38+
$arrayIterator = new \ArrayIterator();
39+
dump($arrayIterator);
40+
$arrayIterator['X'] = 'A';
41+
$arrayIterator['Y'] = new \ArrayIterator(['type' => 'object']);
42+
$arrayIterator['Y']['Z'] = 'B';
43+
44+
$recursiveArrayIterator = new \RecursiveArrayIterator();
45+
dump($recursiveArrayIterator);
46+
$recursiveArrayIterator['X'] = 'A';
47+
$recursiveArrayIterator['Y'] = new \RecursiveArrayIterator(['type' => 'object']);
48+
$recursiveArrayIterator['Y']['Z'] = 'B';
3649

3750
--EXPECTF--
51+
%s on line %d:
3852
ArrayObject {#%d
39-
-storage: []
53+
storage: []
4054
flag::STD_PROP_LIST: false
4155
flag::ARRAY_AS_PROPS: false
4256
iteratorClass: "ArrayIterator"
4357
}
58+
%s on line %d:
59+
ArrayIterator {#%d
60+
storage: []
61+
flag::STD_PROP_LIST: false
62+
flag::ARRAY_AS_PROPS: false
63+
}
64+
%s on line %d:
65+
RecursiveArrayIterator {#%d
66+
storage: []
67+
flag::STD_PROP_LIST: false
68+
flag::ARRAY_AS_PROPS: false
69+
}

src/Symfony/Component/VarDumper/Tests/Integration/dump_data_collector2.phpt

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/Symfony/Component/VarDumper/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"require-dev": {
2424
"ext-iconv": "*",
2525
"symfony/console": "^4.4|^5.0|^6.0",
26+
"symfony/http-kernel": "^4.4|^5.0|^6.0",
2627
"symfony/process": "^4.4|^5.0|^6.0",
2728
"symfony/uid": "^5.1|^6.0",
2829
"twig/twig": "^2.13|^3.0.4"

src/Symfony/Component/VarDumper/phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<testsuites>
1818
<testsuite name="Symfony VarDumper Component Test Suite">
1919
<directory>./Tests/</directory>
20+
<directory suffix=".phpt">./Tests/Dumper/functions/</directory>
2021
</testsuite>
2122
</testsuites>
2223

0 commit comments

Comments
 (0)
0