8000 [VarDumper] Fix dumping of SplObjectStorage · symfony/symfony@b2ac6b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b2ac6b6

Browse files
corphifabpot
authored andcommitted
[VarDumper] Fix dumping of SplObjectStorage
1 parent b97a4ae commit b2ac6b6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $s
8686
$storage = array();
8787
unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967
8888

89-
foreach (clone $c as $obj) {
89+
$clone = clone $c;
90+
foreach ($clone as $obj) {
9091
$storage[spl_object_hash($obj)] = array(
9192
'object' => $obj,
92-
'info' => $c->getInfo(),
93+
'info' => $clone->getInfo(),
9394
);
9495
}
9596

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,23 @@ public function provideCastSplDoublyLinkedList()
4040
array(\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_LIFO | IT_MODE_DELETE'),
4141
);
4242
}
43+
44+
public function testCastObjectStorageIsntModified()
45+
{
46+
$var = new \SplObjectStorage();
47+
$var->attach(new \stdClass());
48+
$var->rewind();
49+
$current = $var->current();
50+
51+
$this->assertDumpMatchesFormat('%A', $var);
52+
$this->assertSame($current, $var->current());
53+
}
54+
55+
public function testCastObjectStorageDumpsInfo()
56+
{
57+
$var = new \SplObjectStorage();
58+
$var->attach(new \stdClass(), new \DateTime());
59+
60+
$this->assertDumpMatchesFormat('%ADateTime%A', $var);
61+
}
4362
}

0 commit comments

Comments
 (0)
0