diff --git a/src/Aspect.php b/src/Aspect.php index 47c0fe7d..ca06be38 100644 --- a/src/Aspect.php +++ b/src/Aspect.php @@ -198,7 +198,7 @@ private function newInstanceWithPhp(string $className, array $args): object private function createBind(string $className): Bind { $bind = new Bind(); - $reflection = new ReflectionClass($className); + $reflection = new \Ray\Aop\ReflectionClass($className); foreach ($this->matchers as $matcher) { if (! $matcher['classMatcher']->matchesClass($reflection, $matcher['classMatcher']->getArguments())) { diff --git a/tests/Aspect/AspectTest.php b/tests/Aspect/AspectTest.php index 9a16dd5c..35c775a3 100644 --- a/tests/Aspect/AspectTest.php +++ b/tests/Aspect/AspectTest.php @@ -5,6 +5,7 @@ namespace Ray\Aop; use PHPUnit\Framework\TestCase; +use Ray\Aop\Annotation\FakeClassMarker; use Ray\Aop\Aspect\Fake\src\FakeMyClass; use Ray\Aop\Matcher\AnyMatcher; use Ray\Aop\Matcher\StartsWithMatcher; @@ -63,4 +64,17 @@ public function testWeave(): void // the original method is intercepted $this->assertEquals('intercepted original', $result); } + + public function testAnnotateMatcher(): void + { + $aspect = new Aspect(); + $aspect->bind( + (new Matcher())->annotatedWith(FakeClassMarker::class), + (new Matcher())->any(), + [new FakeMyInterceptor()] + ); + + $billing = $aspect->newInstance(FakeMyClass::class); + $this->assertInstanceOf(FakeMyClass::class, $billing); + } }