Skip to content

Commit ddc8e2b

Browse files
koriymclaude
andcommitted
Add test for arrays containing objects to validate fix for #125
Adds testInstanceCompileArrayWithObjects to ensure arrays containing objects (e.g., [new DeleteCookieInvoker(), '__invoke']) are properly serialized instead of using var_export(), which would cause fatal errors. This test validates the core issue from #125 where var_export() cannot handle arrays containing objects. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 518f61f commit ddc8e2b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/VisitorCompilerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ public function testInstanceCompileArray(): void
5454
$this->assertSame($expected, $code);
5555
}
5656

57+
public function testInstanceCompileArrayWithObjects(): void
58+
{
59+
$object = new FakeEngine();
60+
$dependencyInstance = new Instance([$object, '__invoke']);
61+
$code = $dependencyInstance->accept($this->visitor);
62+
63+
// Should use unserialize and not crash with var_export
64+
$this->assertStringContainsString('return unserialize(', $code);
65+
66+
// Verify it can be executed and reconstructed
67+
$result = eval($code);
68+
$this->assertIsArray($result);
69+
$this->assertCount(2, $result);
70+
$this->assertInstanceOf(FakeEngine::class, $result[0]);
71+
$this->assertSame('__invoke', $result[1]);
72+
}
73+
5774
public function testDependencyCompile(): Container
5875
{
5976
$module = new FakeCarModule();

0 commit comments

Comments
 (0)