Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with annotated with matcher #219

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading