From 415ddda03d513dfd3dde675f616884149a2be22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kosi=C5=84ski?= Date: Mon, 23 Feb 2026 11:49:42 +0100 Subject: [PATCH 1/2] Symfony attributes for autoconfiguring handlers --- .../AsAsynchronousEventSubscriber.php | 18 ++++++ .../AsAsynchronousMessageHandler.php | 18 ++++++ .../src/SimpleBusAsynchronousBundle.php | 26 ++++++++ .../Functional/Attribute/AttrAsyncCommand.php | 5 ++ .../tests/Functional/Attribute/AttrEvent.php | 5 ++ .../AttributeAsyncCommandHandler.php | 18 ++++++ .../AttributeAsyncEventSubscriber.php | 17 ++++++ .../SimpleBusAsynchronousBundleTest.php | 44 ++++++++++++++ .../tests/Functional/config.yml | 14 +++++ .../src/Attribute/AsEventSubscriber.php | 18 ++++++ .../src/Attribute/AsMessageHandler.php | 18 ++++++ .../AttributeTagResolver.php | 56 ++++++++++++++++++ .../src/SimpleBusCommandBusBundle.php | 23 ++++++++ .../tests/Functional/AttributesTest.php | 59 +++++++++++++++++++ .../SmokeTest/Attributes/AttrCommand.php | 18 ++++++ .../SmokeTest/Attributes/AttrEvent.php | 24 ++++++++ .../Attributes/AttributeCommandHandler.php | 14 +++++ .../Attributes/AttributeEventSubscriber.php | 14 +++++ .../SmokeTest/config_attributes.yml | 8 +++ 19 files changed, 417 insertions(+) create mode 100644 packages/asynchronous-bundle/src/Attribute/AsAsynchronousEventSubscriber.php create mode 100644 packages/asynchronous-bundle/src/Attribute/AsAsynchronousMessageHandler.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommand.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttrEvent.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncCommandHandler.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncEventSubscriber.php create mode 100644 packages/symfony-bridge/src/Attribute/AsEventSubscriber.php create mode 100644 packages/symfony-bridge/src/Attribute/AsMessageHandler.php create mode 100644 packages/symfony-bridge/src/DependencyInjection/AttributeTagResolver.php create mode 100644 packages/symfony-bridge/tests/Functional/AttributesTest.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrCommand.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrEvent.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeCommandHandler.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeEventSubscriber.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/config_attributes.yml diff --git a/packages/asynchronous-bundle/src/Attribute/AsAsynchronousEventSubscriber.php b/packages/asynchronous-bundle/src/Attribute/AsAsynchronousEventSubscriber.php new file mode 100644 index 00000000..2e9bd355 --- /dev/null +++ b/packages/asynchronous-bundle/src/Attribute/AsAsynchronousEventSubscriber.php @@ -0,0 +1,18 @@ +subscribesTo = $subscribesTo; + $this->method = $method; + } +} diff --git a/packages/asynchronous-bundle/src/Attribute/AsAsynchronousMessageHandler.php b/packages/asynchronous-bundle/src/Attribute/AsAsynchronousMessageHandler.php new file mode 100644 index 00000000..0bb8bc14 --- /dev/null +++ b/packages/asynchronous-bundle/src/Attribute/AsAsynchronousMessageHandler.php @@ -0,0 +1,18 @@ +handles = $handles; + $this->method = $method; + } +} diff --git a/packages/asynchronous-bundle/src/SimpleBusAsynchronousBundle.php b/packages/asynchronous-bundle/src/SimpleBusAsynchronousBundle.php index 06deeac8..f5401631 100644 --- a/packages/asynchronous-bundle/src/SimpleBusAsynchronousBundle.php +++ b/packages/asynchronous-bundle/src/SimpleBusAsynchronousBundle.php @@ -2,12 +2,20 @@ namespace SimpleBus\AsynchronousBundle; +use ReflectionMethod; +use ReflectionNamedType; +use ReflectionUnionType; +use Reflector; +use SimpleBus\AsynchronousBundle\Attribute\AsAsynchronousEventSubscriber; +use SimpleBus\AsynchronousBundle\Attribute\AsAsynchronousMessageHandler; use SimpleBus\AsynchronousBundle\DependencyInjection\Compiler\CollectAsynchronousEventNames; use SimpleBus\AsynchronousBundle\DependencyInjection\SimpleBusAsynchronousExtension; +use SimpleBus\SymfonyBridge\DependencyInjection\AttributeTagResolver; use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\AutoRegister; use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\ConfigureMiddlewares; use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\RegisterHandlers; use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\RegisterSubscribers; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -21,6 +29,24 @@ public function getContainerExtension(): SimpleBusAsynchronousExtension public function build(ContainerBuilder $container): void { + $container->registerAttributeForAutoconfiguration( + AsAsynchronousMessageHandler::class, + static function (ChildDefinition $definition, AsAsynchronousMessageHandler $attribute, Reflector $reflector): void { + foreach (AttributeTagResolver::resolveTags($reflector, $attribute->handles, $attribute->method, 'handles') as $tag) { + $definition->addTag('asynchronous_command_handler', $tag); + } + } + ); + + $container->registerAttributeForAutoconfiguration( + AsAsynchronousEventSubscriber::class, + static function (ChildDefinition $definition, AsAsynchronousEventSubscriber $attribute, Reflector $reflector): void { + foreach (AttributeTagResolver::resolveTags($reflector, $attribute->subscribesTo, $attribute->method, 'subscribes_to') as $tag) { + $definition->addTag('asynchronous_event_subscriber', $tag); + } + } + ); + $container->addCompilerPass( new ConfigureMiddlewares('simple_bus.asynchronous.command_bus', 'asynchronous_command_bus_middleware') ); diff --git a/packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommand.php b/packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommand.php new file mode 100644 index 00000000..b35b5849 --- /dev/null +++ b/packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommand.php @@ -0,0 +1,5 @@ +spy->handled[] = $command; + } +} diff --git a/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncEventSubscriber.php b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncEventSubscriber.php new file mode 100644 index 00000000..bc8ab22d --- /dev/null +++ b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncEventSubscriber.php @@ -0,0 +1,17 @@ +spy->handled[] = $event; + } +} diff --git a/packages/asynchronous-bundle/tests/Functional/SimpleBusAsynchronousBundleTest.php b/packages/asynchronous-bundle/tests/Functional/SimpleBusAsynchronousBundleTest.php index 12a2fac2..c9c3f4f5 100644 --- a/packages/asynchronous-bundle/tests/Functional/SimpleBusAsynchronousBundleTest.php +++ b/packages/asynchronous-bundle/tests/Functional/SimpleBusAsynchronousBundleTest.php @@ -3,6 +3,8 @@ namespace SimpleBus\AsynchronousBundle\Tests\Functional; use PHPUnit\Framework\Attributes\Test; +use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrAsyncCommand; +use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrEvent; use SimpleBus\Message\Bus\MessageBus; use SimpleBus\Serialization\Envelope\DefaultEnvelope; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -37,6 +39,48 @@ public function itNotifiesSynchronousEventSubscribersAndPublishesEvents(): void $this->assertSame([$event], $eventPublisher->publishedMessages()); } + #[Test] + public function itNotifiesAsynchronousEventSubscribersUsingAttributes(): void + { + $kernel = static::createKernel(); + $kernel->boot(); + + $event = new AttrEvent(); + + /** @var MessageBus $asynchronousEventBus */ + $asynchronousEventBus = $kernel->getContainer()->get('asynchronous_event_bus'); + $asynchronousEventBus->handle($event); + + /** @var Spy $spy */ + $spy = $kernel->getContainer()->get('spy'); + $this->assertSame([$event], $spy->handled); + + /** @var PublisherSpy $eventPublisher */ + $eventPublisher = $kernel->getContainer()->get('event_publisher_spy'); + $this->assertSame([], $eventPublisher->publishedMessages()); + } + + #[Test] + public function itHandlesAsynchronousCommandsUsingAttributes(): void + { + $kernel = static::createKernel(); + $kernel->boot(); + + $command = new AttrAsyncCommand(); + + /** @var MessageBus $asynchronousCommandBus */ + $asynchronousCommandBus = $kernel->getContainer()->get('asynchronous_command_bus'); + $asynchronousCommandBus->handle($command); + + /** @var PublisherSpy $commandPublisher */ + $commandPublisher = $kernel->getContainer()->get('command_publisher_spy'); + $this->assertSame([], $commandPublisher->publishedMessages()); + + /** @var Spy $spy */ + $spy = $kernel->getContainer()->get('spy'); + $this->assertSame([$command], $spy->handled); + } + #[Test] public function itNotifiesAsynchronousEventSubscribers(): void { diff --git a/packages/asynchronous-bundle/tests/Functional/config.yml b/packages/asynchronous-bundle/tests/Functional/config.yml index 6b0ca353..237b0fdd 100644 --- a/packages/asynchronous-bundle/tests/Functional/config.yml +++ b/packages/asynchronous-bundle/tests/Functional/config.yml @@ -17,6 +17,20 @@ services: public: true class: SimpleBus\AsynchronousBundle\Tests\Functional\Spy + asynchronous_attribute_event_subscriber: + public: false + autoconfigure: true + class: SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttributeAsyncEventSubscriber + arguments: + - '@spy' + + asynchronous_attribute_command_handler: + public: false + autoconfigure: true + class: SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttributeAsyncCommandHandler + arguments: + - '@spy' + synchronous_event_subscriber: public: false class: SimpleBus\AsynchronousBundle\Tests\Functional\EventSubscriber diff --git a/packages/symfony-bridge/src/Attribute/AsEventSubscriber.php b/packages/symfony-bridge/src/Attribute/AsEventSubscriber.php new file mode 100644 index 00000000..32a60a7f --- /dev/null +++ b/packages/symfony-bridge/src/Attribute/AsEventSubscriber.php @@ -0,0 +1,18 @@ +subscribesTo = $subscribesTo; + $this->method = $method; + } +} diff --git a/packages/symfony-bridge/src/Attribute/AsMessageHandler.php b/packages/symfony-bridge/src/Attribute/AsMessageHandler.php new file mode 100644 index 00000000..9853df48 --- /dev/null +++ b/packages/symfony-bridge/src/Attribute/AsMessageHandler.php @@ -0,0 +1,18 @@ +handles = $handles; + $this->method = $method; + } +} diff --git a/packages/symfony-bridge/src/DependencyInjection/AttributeTagResolver.php b/packages/symfony-bridge/src/DependencyInjection/AttributeTagResolver.php new file mode 100644 index 00000000..b35928ff --- /dev/null +++ b/packages/symfony-bridge/src/DependencyInjection/AttributeTagResolver.php @@ -0,0 +1,56 @@ +> + */ + public static function resolveTags( + Reflector $reflector, + ?string $messageType, + ?string $method, + string $typeKey, + ): array { + $resolvedMethod = $method ?? ($reflector instanceof ReflectionMethod ? $reflector->getName() : null); + + if (null === $messageType && $reflector instanceof ReflectionMethod) { + $parameters = $reflector->getParameters(); + if (1 === count($parameters) && !$parameters[0]->isOptional()) { + $type = $parameters[0]->getType(); + + $types = match (true) { + $type instanceof ReflectionNamedType => [$type], + $type instanceof ReflectionUnionType => $type->getTypes(), + default => [], + }; + + $tags = []; + foreach ($types as $namedType) { + if (!$namedType instanceof ReflectionNamedType || $namedType->isBuiltin()) { + continue; + } + $tags[] = array_filter([ + $typeKey => $namedType->getName(), + 'method' => $resolvedMethod, + ]); + } + + return $tags; + } + } + + return [array_filter([ + $typeKey => $messageType, + 'method' => $resolvedMethod, + ])]; + } +} diff --git a/packages/symfony-bridge/src/SimpleBusCommandBusBundle.php b/packages/symfony-bridge/src/SimpleBusCommandBusBundle.php index 3328039b..6fa9a194 100644 --- a/packages/symfony-bridge/src/SimpleBusCommandBusBundle.php +++ b/packages/symfony-bridge/src/SimpleBusCommandBusBundle.php @@ -2,10 +2,15 @@ namespace SimpleBus\SymfonyBridge; +use Reflector; +use SimpleBus\SymfonyBridge\Attribute\AsEventSubscriber; +use SimpleBus\SymfonyBridge\Attribute\AsMessageHandler; +use SimpleBus\SymfonyBridge\DependencyInjection\AttributeTagResolver; use SimpleBus\SymfonyBridge\DependencyInjection\CommandBusExtension; use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\AutoRegister; use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\ConfigureMiddlewares; use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\RegisterHandlers; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -21,6 +26,24 @@ public function __construct(string $alias = 'command_bus') public function build(ContainerBuilder $container): void { + $container->registerAttributeForAutoconfiguration( + AsMessageHandler::class, + static function (ChildDefinition $definition, AsMessageHandler $attribute, Reflector $reflector): void { + foreach (AttributeTagResolver::resolveTags($reflector, $attribute->handles, $attribute->method, 'handles') as $tag) { + $definition->addTag('command_handler', $tag); + } + } + ); + + $container->registerAttributeForAutoconfiguration( + AsEventSubscriber::class, + static function (ChildDefinition $definition, AsEventSubscriber $attribute, Reflector $reflector): void { + foreach (AttributeTagResolver::resolveTags($reflector, $attribute->subscribesTo, $attribute->method, 'subscribes_to') as $tag) { + $definition->addTag('event_subscriber', $tag); + } + } + ); + $container->addCompilerPass( new AutoRegister('command_handler', 'handles'), PassConfig::TYPE_BEFORE_OPTIMIZATION, diff --git a/packages/symfony-bridge/tests/Functional/AttributesTest.php b/packages/symfony-bridge/tests/Functional/AttributesTest.php new file mode 100644 index 00000000..072b1554 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/AttributesTest.php @@ -0,0 +1,59 @@ + 'config_attributes']); + $container = self::getContainer(); + + $command = new AttrCommand(); + + $commandBus = $container->get('command_bus'); + $this->assertInstanceOf(MessageBus::class, $commandBus); + + $commandBus->handle($command); + + $this->assertTrue($command->isHandled()); + } + + #[Test] + public function itCanRegisterEventSubscriberUsingAttribute(): void + { + self::bootKernel(['environment' => 'config_attributes']); + $container = self::getContainer(); + + $event = new AttrEvent(); + + $eventBus = $container->get('event_bus'); + $this->assertInstanceOf(MessageBus::class, $eventBus); + + $eventBus->handle($event); + + $this->assertTrue($event->isHandledBy( + SmokeTest\Attributes\AttributeEventSubscriber::class + )); + } + + protected static function getKernelClass(): string + { + return TestKernel::class; + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrCommand.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrCommand.php new file mode 100644 index 00000000..34310721 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrCommand.php @@ -0,0 +1,18 @@ +handled; + } + + public function setHandled(bool $handled): void + { + $this->handled = $handled; + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrEvent.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrEvent.php new file mode 100644 index 00000000..a3a25f8b --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrEvent.php @@ -0,0 +1,24 @@ +handled, true); + } + + public function setHandledBy(object $subscriber): void + { + $this->handled[] = get_class($subscriber); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeCommandHandler.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeCommandHandler.php new file mode 100644 index 00000000..01e72c2c --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeCommandHandler.php @@ -0,0 +1,14 @@ +setHandled(true); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeEventSubscriber.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeEventSubscriber.php new file mode 100644 index 00000000..fafc56a2 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeEventSubscriber.php @@ -0,0 +1,14 @@ +setHandledBy($this); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/config_attributes.yml b/packages/symfony-bridge/tests/Functional/SmokeTest/config_attributes.yml new file mode 100644 index 00000000..4e9120ba --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/config_attributes.yml @@ -0,0 +1,8 @@ +imports: + - { resource: config.yml } + +services: + SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\: + resource: '%kernel.project_dir%/Attributes/*' + public: false + autoconfigure: true From c8da9ced7c1f378d41d992a0acc72a0ad3fd5589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kosi=C5=84ski?= Date: Mon, 23 Feb 2026 13:27:43 +0100 Subject: [PATCH 2/2] Try to resolve from handle method, tests --- ...ageHandler.php => AsyncCommandHandler.php} | 6 +- ...tSubscriber.php => AsyncEventListener.php} | 6 +- .../src/SimpleBusAsynchronousBundle.php | 15 +-- .../Attribute/AttrAsyncCommandA.php | 5 + .../Attribute/AttrAsyncCommandB.php | 5 + .../Attribute/AttrAsyncCommandC.php | 5 + .../Attribute/AttrAsyncCommandD.php | 5 + .../Attribute/AttrAsyncCommandE.php | 5 + .../Attribute/AttrAsyncCommandF.php | 5 + .../AttributeAsyncCommandHandler.php | 5 +- .../AttributeAsyncEventSubscriber.php | 4 +- .../AttributeUnionAsyncCommandHandler.php | 17 +++ ...ributeUnionAsyncCommandHandlerExplicit.php | 17 +++ ...tributeUnionAsyncCommandHandlerProcess.php | 17 +++ .../SimpleBusAsynchronousBundleTest.php | 79 ++++++++++++ .../tests/Functional/config.yml | 21 +++ ...sMessageHandler.php => CommandHandler.php} | 6 +- ...sEventSubscriber.php => EventListener.php} | 6 +- .../AttributeTagResolver.php | 59 +++++---- .../src/SimpleBusCommandBusBundle.php | 12 +- .../tests/Functional/AttributesTest.php | 120 ++++++++++++++++++ .../Attributes/AttrUnionCommandA.php | 18 +++ .../Attributes/AttrUnionCommandB.php | 18 +++ .../Attributes/AttrUnionCommandC.php | 18 +++ .../Attributes/AttrUnionCommandD.php | 18 +++ .../Attributes/AttrUnionCommandE.php | 18 +++ .../Attributes/AttrUnionCommandF.php | 18 +++ .../SmokeTest/Attributes/AttrUnionEventA.php | 19 +++ .../SmokeTest/Attributes/AttrUnionEventB.php | 19 +++ .../SmokeTest/Attributes/AttrUnionEventC.php | 19 +++ .../SmokeTest/Attributes/AttrUnionEventD.php | 19 +++ .../SmokeTest/Attributes/AttrUnionEventG.php | 19 +++ .../SmokeTest/Attributes/AttrUnionEventH.php | 19 +++ .../Attributes/AttributeCommandHandler.php | 4 +- .../Attributes/AttributeEventSubscriber.php | 4 +- .../AttributeUnionCommandHandler.php | 14 ++ .../AttributeUnionCommandHandlerExplicit.php | 15 +++ .../AttributeUnionCommandHandlerProcess.php | 14 ++ .../AttributeUnionEventListener.php | 14 ++ .../AttributeUnionEventListenerExplicit.php | 14 ++ .../AttributeUnionEventListenerOn.php | 14 ++ 41 files changed, 680 insertions(+), 55 deletions(-) rename packages/asynchronous-bundle/src/Attribute/{AsAsynchronousMessageHandler.php => AsyncCommandHandler.php} (84%) rename packages/asynchronous-bundle/src/Attribute/{AsAsynchronousEventSubscriber.php => AsyncEventListener.php} (84%) create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandA.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandB.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandC.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandD.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandE.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandF.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandler.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandlerExplicit.php create mode 100644 packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandlerProcess.php rename packages/symfony-bridge/src/Attribute/{AsMessageHandler.php => CommandHandler.php} (86%) rename packages/symfony-bridge/src/Attribute/{AsEventSubscriber.php => EventListener.php} (86%) create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandA.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandB.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandC.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandD.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandE.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandF.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventA.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventB.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventC.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventD.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventG.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventH.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandler.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandlerExplicit.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandlerProcess.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListener.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListenerExplicit.php create mode 100644 packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListenerOn.php diff --git a/packages/asynchronous-bundle/src/Attribute/AsAsynchronousMessageHandler.php b/packages/asynchronous-bundle/src/Attribute/AsyncCommandHandler.php similarity index 84% rename from packages/asynchronous-bundle/src/Attribute/AsAsynchronousMessageHandler.php rename to packages/asynchronous-bundle/src/Attribute/AsyncCommandHandler.php index 0bb8bc14..2093215f 100644 --- a/packages/asynchronous-bundle/src/Attribute/AsAsynchronousMessageHandler.php +++ b/packages/asynchronous-bundle/src/Attribute/AsyncCommandHandler.php @@ -1,11 +1,13 @@ -registerAttributeForAutoconfiguration( - AsAsynchronousMessageHandler::class, - static function (ChildDefinition $definition, AsAsynchronousMessageHandler $attribute, Reflector $reflector): void { + AsyncCommandHandler::class, + static function (ChildDefinition $definition, AsyncCommandHandler $attribute, Reflector $reflector): void { foreach (AttributeTagResolver::resolveTags($reflector, $attribute->handles, $attribute->method, 'handles') as $tag) { $definition->addTag('asynchronous_command_handler', $tag); } @@ -39,8 +36,8 @@ static function (ChildDefinition $definition, AsAsynchronousMessageHandler $attr ); $container->registerAttributeForAutoconfiguration( - AsAsynchronousEventSubscriber::class, - static function (ChildDefinition $definition, AsAsynchronousEventSubscriber $attribute, Reflector $reflector): void { + AsyncEventListener::class, + static function (ChildDefinition $definition, AsyncEventListener $attribute, Reflector $reflector): void { foreach (AttributeTagResolver::resolveTags($reflector, $attribute->subscribesTo, $attribute->method, 'subscribes_to') as $tag) { $definition->addTag('asynchronous_event_subscriber', $tag); } diff --git a/packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandA.php b/packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandA.php new file mode 100644 index 00000000..24d8d198 --- /dev/null +++ b/packages/asynchronous-bundle/tests/Functional/Attribute/AttrAsyncCommandA.php @@ -0,0 +1,5 @@ +spy->handled[] = $command; diff --git a/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncEventSubscriber.php b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncEventSubscriber.php index bc8ab22d..f4292083 100644 --- a/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncEventSubscriber.php +++ b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeAsyncEventSubscriber.php @@ -2,10 +2,10 @@ namespace SimpleBus\AsynchronousBundle\Tests\Functional\Attribute; -use SimpleBus\AsynchronousBundle\Attribute\AsAsynchronousEventSubscriber; +use SimpleBus\AsynchronousBundle\Attribute\AsyncEventListener; use SimpleBus\AsynchronousBundle\Tests\Functional\Spy; -#[AsAsynchronousEventSubscriber] +#[AsyncEventListener] final class AttributeAsyncEventSubscriber { public function __construct(private Spy $spy) {} diff --git a/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandler.php b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandler.php new file mode 100644 index 00000000..25af29de --- /dev/null +++ b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandler.php @@ -0,0 +1,17 @@ +spy->handled[] = $command; + } +} diff --git a/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandlerExplicit.php b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandlerExplicit.php new file mode 100644 index 00000000..9f8d4bd2 --- /dev/null +++ b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandlerExplicit.php @@ -0,0 +1,17 @@ +spy->handled[] = $command; + } +} diff --git a/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandlerProcess.php b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandlerProcess.php new file mode 100644 index 00000000..6f4f3321 --- /dev/null +++ b/packages/asynchronous-bundle/tests/Functional/Attribute/AttributeUnionAsyncCommandHandlerProcess.php @@ -0,0 +1,17 @@ +spy->handled[] = $command; + } +} diff --git a/packages/asynchronous-bundle/tests/Functional/SimpleBusAsynchronousBundleTest.php b/packages/asynchronous-bundle/tests/Functional/SimpleBusAsynchronousBundleTest.php index c9c3f4f5..20e9e25b 100644 --- a/packages/asynchronous-bundle/tests/Functional/SimpleBusAsynchronousBundleTest.php +++ b/packages/asynchronous-bundle/tests/Functional/SimpleBusAsynchronousBundleTest.php @@ -4,6 +4,12 @@ use PHPUnit\Framework\Attributes\Test; use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrAsyncCommand; +use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrAsyncCommandA; +use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrAsyncCommandB; +use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrAsyncCommandC; +use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrAsyncCommandD; +use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrAsyncCommandE; +use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrAsyncCommandF; use SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttrEvent; use SimpleBus\Message\Bus\MessageBus; use SimpleBus\Serialization\Envelope\DefaultEnvelope; @@ -81,6 +87,79 @@ public function itHandlesAsynchronousCommandsUsingAttributes(): void $this->assertSame([$command], $spy->handled); } + #[Test] + public function itHandlesUnionTypedCommandsInferredFromHandleMethodOnClassAttribute(): void + { + $kernel = static::createKernel(); + $kernel->boot(); + + $a = new AttrAsyncCommandA(); + $b = new AttrAsyncCommandB(); + + /** @var MessageBus $asynchronousCommandBus */ + $asynchronousCommandBus = $kernel->getContainer()->get('asynchronous_command_bus'); + $asynchronousCommandBus->handle($a); + $asynchronousCommandBus->handle($b); + + /** @var PublisherSpy $commandPublisher */ + $commandPublisher = $kernel->getContainer()->get('command_publisher_spy'); + $this->assertSame([], $commandPublisher->publishedMessages()); + + /** @var Spy $spy */ + $spy = $kernel->getContainer()->get('spy'); + $this->assertSame([$a, $b], $spy->handled); + } + + #[Test] + public function itHandlesUnionTypedCommandsWhenMethodIsSpecifiedOnClassAttribute(): void + { + $kernel = static::createKernel(); + $kernel->boot(); + + $c = new AttrAsyncCommandC(); + $d = new AttrAsyncCommandD(); + + /** @var MessageBus $asynchronousCommandBus */ + $asynchronousCommandBus = $kernel->getContainer()->get('asynchronous_command_bus'); + $asynchronousCommandBus->handle($c); + $asynchronousCommandBus->handle($d); + + /** @var PublisherSpy $commandPublisher */ + $commandPublisher = $kernel->getContainer()->get('command_publisher_spy'); + $this->assertSame([], $commandPublisher->publishedMessages()); + + /** @var Spy $spy */ + $spy = $kernel->getContainer()->get('spy'); + $this->assertSame([$c, $d], $spy->handled); + } + + #[Test] + public function itHonorsExplicitHandlesOnClassAttributeEvenWithUnionTypedMethod(): void + { + $kernel = static::createKernel(); + $kernel->boot(); + + $e = new AttrAsyncCommandE(); + $f = new AttrAsyncCommandF(); + + /** @var MessageBus $asynchronousCommandBus */ + $asynchronousCommandBus = $kernel->getContainer()->get('asynchronous_command_bus'); + $asynchronousCommandBus->handle($e); + + // Send unhandled command through the synchronous command bus to be published + /** @var MessageBus $commandBus */ + $commandBus = $kernel->getContainer()->get('command_bus'); + $commandBus->handle($f); + + /** @var Spy $spy */ + $spy = $kernel->getContainer()->get('spy'); + $this->assertSame([$e], $spy->handled, 'Only explicitly handled message should be handled'); + + /** @var PublisherSpy $commandPublisher */ + $commandPublisher = $kernel->getContainer()->get('command_publisher_spy'); + $this->assertSame([$f], $commandPublisher->publishedMessages(), 'Unhandled union branch should be published'); + } + #[Test] public function itNotifiesAsynchronousEventSubscribers(): void { diff --git a/packages/asynchronous-bundle/tests/Functional/config.yml b/packages/asynchronous-bundle/tests/Functional/config.yml index 237b0fdd..0f13a5e2 100644 --- a/packages/asynchronous-bundle/tests/Functional/config.yml +++ b/packages/asynchronous-bundle/tests/Functional/config.yml @@ -31,6 +31,27 @@ services: arguments: - '@spy' + asynchronous_attribute_union_command_handler: + public: false + autoconfigure: true + class: SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttributeUnionAsyncCommandHandler + arguments: + - '@spy' + + asynchronous_attribute_union_command_handler_process: + public: false + autoconfigure: true + class: SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttributeUnionAsyncCommandHandlerProcess + arguments: + - '@spy' + + asynchronous_attribute_union_command_handler_explicit: + public: false + autoconfigure: true + class: SimpleBus\AsynchronousBundle\Tests\Functional\Attribute\AttributeUnionAsyncCommandHandlerExplicit + arguments: + - '@spy' + synchronous_event_subscriber: public: false class: SimpleBus\AsynchronousBundle\Tests\Functional\EventSubscriber diff --git a/packages/symfony-bridge/src/Attribute/AsMessageHandler.php b/packages/symfony-bridge/src/Attribute/CommandHandler.php similarity index 86% rename from packages/symfony-bridge/src/Attribute/AsMessageHandler.php rename to packages/symfony-bridge/src/Attribute/CommandHandler.php index 9853df48..30c50954 100644 --- a/packages/symfony-bridge/src/Attribute/AsMessageHandler.php +++ b/packages/symfony-bridge/src/Attribute/CommandHandler.php @@ -1,11 +1,13 @@ -getName() : null); - - if (null === $messageType && $reflector instanceof ReflectionMethod) { - $parameters = $reflector->getParameters(); - if (1 === count($parameters) && !$parameters[0]->isOptional()) { - $type = $parameters[0]->getType(); - - $types = match (true) { - $type instanceof ReflectionNamedType => [$type], - $type instanceof ReflectionUnionType => $type->getTypes(), - default => [], - }; - - $tags = []; - foreach ($types as $namedType) { - if (!$namedType instanceof ReflectionNamedType || $namedType->isBuiltin()) { - continue; + $resolvedMethod = $method + ?? ($reflector instanceof ReflectionMethod ? $reflector->getName() : null) + ?? ($reflector instanceof ReflectionClass && $reflector->hasMethod('handle') && !$reflector->hasMethod('__invoke') ? 'handle' : null); + + if (null === $messageType) { + $reflectionMethod = match (true) { + $reflector instanceof ReflectionMethod => $reflector, + $reflector instanceof ReflectionClass && null !== $method => $reflector->getMethod($method), + $reflector instanceof ReflectionClass && $reflector->hasMethod('__invoke') => $reflector->getMethod('__invoke'), + $reflector instanceof ReflectionClass && $reflector->hasMethod('handle') => $reflector->getMethod('handle'), + default => null, + }; + + if (null !== $reflectionMethod) { + $parameters = $reflectionMethod->getParameters(); + if (1 === count($parameters) && !$parameters[0]->isOptional()) { + $type = $parameters[0]->getType(); + + $types = match (true) { + $type instanceof ReflectionNamedType => [$type], + $type instanceof ReflectionUnionType => $type->getTypes(), + default => [], + }; + + $tags = []; + foreach ($types as $namedType) { + if (!$namedType instanceof ReflectionNamedType || $namedType->isBuiltin()) { + continue; + } + $tags[] = array_filter([ + $typeKey => $namedType->getName(), + 'method' => $resolvedMethod, + ]); } - $tags[] = array_filter([ - $typeKey => $namedType->getName(), - 'method' => $resolvedMethod, - ]); - } - return $tags; + return $tags; + } } } diff --git a/packages/symfony-bridge/src/SimpleBusCommandBusBundle.php b/packages/symfony-bridge/src/SimpleBusCommandBusBundle.php index 6fa9a194..17a27557 100644 --- a/packages/symfony-bridge/src/SimpleBusCommandBusBundle.php +++ b/packages/symfony-bridge/src/SimpleBusCommandBusBundle.php @@ -3,8 +3,8 @@ namespace SimpleBus\SymfonyBridge; use Reflector; -use SimpleBus\SymfonyBridge\Attribute\AsEventSubscriber; -use SimpleBus\SymfonyBridge\Attribute\AsMessageHandler; +use SimpleBus\SymfonyBridge\Attribute\CommandHandler; +use SimpleBus\SymfonyBridge\Attribute\EventListener; use SimpleBus\SymfonyBridge\DependencyInjection\AttributeTagResolver; use SimpleBus\SymfonyBridge\DependencyInjection\CommandBusExtension; use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\AutoRegister; @@ -27,8 +27,8 @@ public function __construct(string $alias = 'command_bus') public function build(ContainerBuilder $container): void { $container->registerAttributeForAutoconfiguration( - AsMessageHandler::class, - static function (ChildDefinition $definition, AsMessageHandler $attribute, Reflector $reflector): void { + CommandHandler::class, + static function (ChildDefinition $definition, CommandHandler $attribute, Reflector $reflector): void { foreach (AttributeTagResolver::resolveTags($reflector, $attribute->handles, $attribute->method, 'handles') as $tag) { $definition->addTag('command_handler', $tag); } @@ -36,8 +36,8 @@ static function (ChildDefinition $definition, AsMessageHandler $attribute, Refle ); $container->registerAttributeForAutoconfiguration( - AsEventSubscriber::class, - static function (ChildDefinition $definition, AsEventSubscriber $attribute, Reflector $reflector): void { + EventListener::class, + static function (ChildDefinition $definition, EventListener $attribute, Reflector $reflector): void { foreach (AttributeTagResolver::resolveTags($reflector, $attribute->subscribesTo, $attribute->method, 'subscribes_to') as $tag) { $definition->addTag('event_subscriber', $tag); } diff --git a/packages/symfony-bridge/tests/Functional/AttributesTest.php b/packages/symfony-bridge/tests/Functional/AttributesTest.php index 072b1554..0e765de4 100644 --- a/packages/symfony-bridge/tests/Functional/AttributesTest.php +++ b/packages/symfony-bridge/tests/Functional/AttributesTest.php @@ -6,6 +6,18 @@ use SimpleBus\Message\Bus\MessageBus; use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrCommand; use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrEvent; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionCommandA; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionCommandB; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionCommandC; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionCommandD; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionCommandE; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionCommandF; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionEventA; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionEventB; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionEventC; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionEventD; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionEventG; +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes\AttrUnionEventH; use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\TestKernel; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -52,6 +64,114 @@ public function itCanRegisterEventSubscriberUsingAttribute(): void )); } + #[Test] + public function itCanRegisterUnionCommandHandlersUsingAttribute(): void + { + self::bootKernel(['environment' => 'config_attributes']); + $container = self::getContainer(); + + $a = new AttrUnionCommandA(); + $b = new AttrUnionCommandB(); + + /** @var MessageBus $commandBus */ + $commandBus = $container->get('command_bus'); + $commandBus->handle($a); + $commandBus->handle($b); + + $this->assertTrue($a->isHandled()); + $this->assertTrue($b->isHandled()); + } + + #[Test] + public function itCanRegisterUnionCommandHandlersWithMethodUsingAttribute(): void + { + self::bootKernel(['environment' => 'config_attributes']); + $container = self::getContainer(); + + $c = new AttrUnionCommandC(); + $d = new AttrUnionCommandD(); + + /** @var MessageBus $commandBus */ + $commandBus = $container->get('command_bus'); + $commandBus->handle($c); + $commandBus->handle($d); + + $this->assertTrue($c->isHandled()); + $this->assertTrue($d->isHandled()); + } + + #[Test] + public function itHonorsExplicitHandlesOnUnionCommandHandler(): void + { + self::bootKernel(['environment' => 'config_attributes']); + $container = self::getContainer(); + + $e = new AttrUnionCommandE(); + $f = new AttrUnionCommandF(); + + /** @var MessageBus $commandBus */ + $commandBus = $container->get('command_bus'); + $commandBus->handle($e); + $commandBus->handle($f); + + $this->assertTrue($e->isHandled()); + $this->assertTrue($f->isHandled()); + } + + #[Test] + public function itCanRegisterUnionEventListenersUsingAttribute(): void + { + self::bootKernel(['environment' => 'config_attributes']); + $container = self::getContainer(); + + $a = new AttrUnionEventA(); + $b = new AttrUnionEventB(); + + /** @var MessageBus $eventBus */ + $eventBus = $container->get('event_bus'); + $eventBus->handle($a); + $eventBus->handle($b); + + $this->assertTrue($a->isHandledBy(SmokeTest\Attributes\AttributeUnionEventListener::class)); + $this->assertTrue($b->isHandledBy(SmokeTest\Attributes\AttributeUnionEventListener::class)); + } + + #[Test] + public function itCanRegisterUnionEventListenersWithMethodUsingAttribute(): void + { + self::bootKernel(['environment' => 'config_attributes']); + $container = self::getContainer(); + + $c = new AttrUnionEventC(); + $d = new AttrUnionEventD(); + + /** @var MessageBus $eventBus */ + $eventBus = $container->get('event_bus'); + $eventBus->handle($c); + $eventBus->handle($d); + + $this->assertTrue($c->isHandledBy(SmokeTest\Attributes\AttributeUnionEventListenerOn::class)); + $this->assertTrue($d->isHandledBy(SmokeTest\Attributes\AttributeUnionEventListenerOn::class)); + } + + #[Test] + public function itHonorsExplicitSubscribesToOnUnionEventListener(): void + { + self::bootKernel(['environment' => 'config_attributes']); + $container = self::getContainer(); + + $g = new AttrUnionEventG(); + $h = new AttrUnionEventH(); + + /** @var MessageBus $eventBus */ + $eventBus = $container->get('event_bus'); + $eventBus->handle($g); + $eventBus->handle($h); + + $this->assertTrue($g->isHandledBy(SmokeTest\Attributes\AttributeUnionEventListenerExplicit::class)); + $this->assertFalse($h->isHandledBy(SmokeTest\Attributes\AttributeUnionEventListenerExplicit::class), 'Event not explicitly subscribed should not be handled'); + } + protected static function getKernelClass(): string { return TestKernel::class; diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandA.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandA.php new file mode 100644 index 00000000..883943d5 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandA.php @@ -0,0 +1,18 @@ +handled; + } + + public function setHandled(bool $handled): void + { + $this->handled = $handled; + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandB.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandB.php new file mode 100644 index 00000000..517422a3 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandB.php @@ -0,0 +1,18 @@ +handled; + } + + public function setHandled(bool $handled): void + { + $this->handled = $handled; + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandC.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandC.php new file mode 100644 index 00000000..679b1793 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandC.php @@ -0,0 +1,18 @@ +handled; + } + + public function setHandled(bool $handled): void + { + $this->handled = $handled; + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandD.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandD.php new file mode 100644 index 00000000..61c9ac0b --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandD.php @@ -0,0 +1,18 @@ +handled; + } + + public function setHandled(bool $handled): void + { + $this->handled = $handled; + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandE.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandE.php new file mode 100644 index 00000000..415b3b36 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandE.php @@ -0,0 +1,18 @@ +handled; + } + + public function setHandled(bool $handled): void + { + $this->handled = $handled; + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandF.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandF.php new file mode 100644 index 00000000..ebcde888 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionCommandF.php @@ -0,0 +1,18 @@ +handled; + } + + public function setHandled(bool $handled): void + { + $this->handled = $handled; + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventA.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventA.php new file mode 100644 index 00000000..80479525 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventA.php @@ -0,0 +1,19 @@ +handled, true); + } + + public function setHandledBy(object $subscriber): void + { + $this->handled[] = get_class($subscriber); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventB.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventB.php new file mode 100644 index 00000000..14a03da7 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventB.php @@ -0,0 +1,19 @@ +handled, true); + } + + public function setHandledBy(object $subscriber): void + { + $this->handled[] = get_class($subscriber); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventC.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventC.php new file mode 100644 index 00000000..0c9a5c2c --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventC.php @@ -0,0 +1,19 @@ +handled, true); + } + + public function setHandledBy(object $subscriber): void + { + $this->handled[] = get_class($subscriber); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventD.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventD.php new file mode 100644 index 00000000..0f33de03 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventD.php @@ -0,0 +1,19 @@ +handled, true); + } + + public function setHandledBy(object $subscriber): void + { + $this->handled[] = get_class($subscriber); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventG.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventG.php new file mode 100644 index 00000000..615ffb7e --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventG.php @@ -0,0 +1,19 @@ +handled, true); + } + + public function setHandledBy(object $subscriber): void + { + $this->handled[] = get_class($subscriber); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventH.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventH.php new file mode 100644 index 00000000..5536b0f0 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttrUnionEventH.php @@ -0,0 +1,19 @@ +handled, true); + } + + public function setHandledBy(object $subscriber): void + { + $this->handled[] = get_class($subscriber); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeCommandHandler.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeCommandHandler.php index 01e72c2c..4f95aff1 100644 --- a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeCommandHandler.php +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeCommandHandler.php @@ -2,9 +2,9 @@ namespace SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes; -use SimpleBus\SymfonyBridge\Attribute\AsMessageHandler; +use SimpleBus\SymfonyBridge\Attribute\CommandHandler; -#[AsMessageHandler] +#[CommandHandler] final class AttributeCommandHandler { public function __invoke(AttrCommand $command): void diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeEventSubscriber.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeEventSubscriber.php index fafc56a2..ec5d25d7 100644 --- a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeEventSubscriber.php +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeEventSubscriber.php @@ -2,9 +2,9 @@ namespace SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Attributes; -use SimpleBus\SymfonyBridge\Attribute\AsEventSubscriber; +use SimpleBus\SymfonyBridge\Attribute\EventListener; -#[AsEventSubscriber] +#[EventListener] final class AttributeEventSubscriber { public function __invoke(AttrEvent $event): void diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandler.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandler.php new file mode 100644 index 00000000..3f61dcc0 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandler.php @@ -0,0 +1,14 @@ +setHandled(true); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandlerExplicit.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandlerExplicit.php new file mode 100644 index 00000000..6d40dbaf --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandlerExplicit.php @@ -0,0 +1,15 @@ +setHandled(true); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandlerProcess.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandlerProcess.php new file mode 100644 index 00000000..a71708b1 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionCommandHandlerProcess.php @@ -0,0 +1,14 @@ +setHandled(true); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListener.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListener.php new file mode 100644 index 00000000..885a2ff4 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListener.php @@ -0,0 +1,14 @@ +setHandledBy($this); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListenerExplicit.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListenerExplicit.php new file mode 100644 index 00000000..6a463531 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListenerExplicit.php @@ -0,0 +1,14 @@ +setHandledBy($this); + } +} diff --git a/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListenerOn.php b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListenerOn.php new file mode 100644 index 00000000..8339ef19 --- /dev/null +++ b/packages/symfony-bridge/tests/Functional/SmokeTest/Attributes/AttributeUnionEventListenerOn.php @@ -0,0 +1,14 @@ +setHandledBy($this); + } +}