8000 [VarDumper] fix dumping uninitialized SplFileInfo · symfony/symfony@7d8450e · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d8450e

Browse files
[VarDumper] fix dumping uninitialized SplFileInfo
1 parent e7f7041 commit 7d8450e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNe
9090

9191
$prefix = Caster::PREFIX_VIRTUAL;
9292

93+
if (false === $c->getPathname()) {
94+
$a[$prefix.''] = 'The parent constructor was not called: the object is in an invalid state';
95+
96+
return $a;
97+
}
98+
9399
foreach ($map as $key => $accessor) {
94100
try {
95101
$a[$prefix.$key] = $c->$accessor();

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,32 @@ public function testArrayIterator()
205205
EOTXT;
206206
$this->assertDumpEquals($expected, $var);
207207
}
208+
209+
public function testBadSplFileInfo()
210+
{
211+
if (\defined('HHVM_VERSION')) {
212+
$this->markTestSkipped('HHVM as different internal details.');
213+
}
214+
$var = new BadSplFileInfo();
215+
216+
$expected = <<<EOTXT
217+
Symfony\Component\VarDumper\Tests\Caster\BadSplFileInfo {
218+
⚠: "The parent constructor was not called: the object is in an invalid state"
219+
}
220+
EOTXT;
221+
$this->assertDumpEquals($expected, $var);
222+
223+
}
208224
}
209225

210226
class MyArrayIterator extends \ArrayIterator
211227
{
212228
private $foo = 123;
213229
}
230+
231+
class BadSplFileInfo extends \SplFileInfo
232+
{
233+
public function __construct()
234+
{
235+
}
236+
}

0 commit comments

Comments
 (0)
0