8000 [VarDumper] fix dumping uninitialized SplFileInfo by nicolas-grekas · Pull Request #33841 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] fix dumping uninitialized SplFileInfo #33841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[VarDumper] fix dumping uninitialized SplFileInfo
  • Loading branch information
nicolas-grekas committed Oct 4, 2019
commit b0f42333a59ff8e7a443ec8658c182725a2fb9bd
6 changes: 6 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/SplCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNe

$prefix = Caster::PREFIX_VIRTUAL;

if (false === $c->getPathname()) {
$a[$prefix.'⚠'] = 'The parent constructor was not called: the object is in an invalid state';

return $a;
}

foreach ($map as $key => $accessor) {
try {
$a[$prefix.$key] = $c->$accessor();
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ public function testArrayIterator()
0 => 234
]
}
EOTXT;
$this->assertDumpEquals($expected, $var);
}

public function testBadSplFileInfo()
{
$var = new BadSplFileInfo();

$expected = <<<EOTXT
Symfony\Component\VarDumper\Tests\Caster\BadSplFileInfo {
⚠: "The parent constructor was not called: the object is in an invalid state"
}
EOTXT;
$this->assertDumpEquals($expected, $var);
}
Expand All @@ -211,3 +223,10 @@ class MyArrayIterator extends \ArrayIterator
{
private $foo = 123;
}

class BadSplFileInfo extends \SplFileInfo
{
public function __construct()
{
}
}
0