diff --git a/src/CodeVisitor.php b/src/CodeVisitor.php index da87f6e4..c9662660 100644 --- a/src/CodeVisitor.php +++ b/src/CodeVisitor.php @@ -73,7 +73,7 @@ private function validateClass(Class_ $class): void */ private function enterNodeClass(Node $node) { - if ($node instanceof Class_) { + if ($node instanceof Class_ && $node->name !== null) { $this->validateClass($node); $this->class = $node; diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index 151505f9..2dbb2f8f 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -353,4 +353,11 @@ public function testCompileMultipleFile(): void $bind = (new Bind())->bindInterceptors('foo', [new FakeDoubleInterceptor()]); $compiler->newInstance(FakeTwoClass::class, [], $bind); } + + public function testNewInstanceWithAnonymousClass(): void + { + $mock = $this->compiler->newInstance(FakeAnonymousClass::class, [], $this->bind); + $this->assertInstanceOf(FakeAnonymousClass::class, $mock); + $this->assertInstanceOf(WeavedInterface::class, $mock); + } } diff --git a/tests/Fake/FakeAnonymousClass.php b/tests/Fake/FakeAnonymousClass.php new file mode 100644 index 00000000..2eedb374 --- /dev/null +++ b/tests/Fake/FakeAnonymousClass.php @@ -0,0 +1,13 @@ +