From 6f54fea9741b0ac600daa9efe0bc113b5f1ac99a Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 22 May 2024 16:49:46 +0400 Subject: [PATCH] Fix listener --- src/DeclarationLocator.php | 10 +++++----- tests/src/DeclarationLocatorTest.php | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/DeclarationLocator.php b/src/DeclarationLocator.php index 0f83201..7c5cff9 100644 --- a/src/DeclarationLocator.php +++ b/src/DeclarationLocator.php @@ -14,8 +14,8 @@ use Temporal\Workflow\WorkflowInterface; #[Singleton] -#[TargetAttribute(WorkflowInterface::class)] -#[TargetAttribute(ActivityInterface::class)] +// #[TargetAttribute(WorkflowInterface::class)] +// #[TargetAttribute(ActivityInterface::class)] final class DeclarationLocator implements DeclarationRegistryInterface, TokenizationListenerInterface, @@ -63,13 +63,13 @@ public function listen(\ReflectionClass $class): void /** @var DeclarationType|null $type */ $type = null; - foreach (\array_merge($class->getInterfaces(), [$class]) as $type) { - if ($this->reader->firstClassMetadata($type, WorkflowInterface::class) !== null) { + foreach (\array_merge($class->getInterfaces(), [$class]) as $reflection) { + if ($this->reader->firstClassMetadata($reflection, WorkflowInterface::class) !== null) { $type = DeclarationType::Workflow; break; } - if ($this->reader->firstClassMetadata($type, ActivityInterface::class) !== null) { + if ($this->reader->firstClassMetadata($reflection, ActivityInterface::class) !== null) { $type = DeclarationType::Activity; break; } diff --git a/tests/src/DeclarationLocatorTest.php b/tests/src/DeclarationLocatorTest.php index f0524b5..6e667b5 100644 --- a/tests/src/DeclarationLocatorTest.php +++ b/tests/src/DeclarationLocatorTest.php @@ -181,6 +181,19 @@ class: new \ReflectionClass(TestActivityClassWithInterface::class), $this->assertSame(ActivityInterface::class, $result[3][0]); $this->assertSame(TestActivityClassWithInterface::class, $result[3][1]->getName()); } + + public function testWrongClasses(): void + { + $this->locator->listen(new \ReflectionClass(\stdClass::class)); + + $result = []; + + foreach ($this->locator->getDeclarations() as $type => $class) { + $result[] = [$type, $class]; + } + + $this->assertCount(0, $result); + } } enum TestEnum