Skip to content

Commit

Permalink
Merge pull request #219 from ray-di/bug-with-AnnotatedWithMatcher
Browse files Browse the repository at this point in the history
Bug with annotated with matcher
  • Loading branch information
koriym authored Sep 3, 2024
2 parents 1b2d410 + 5e88adb commit e7df832
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Aspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
14 changes: 14 additions & 0 deletions tests/Aspect/AspectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit e7df832

Please sign in to comment.