From 8fda19e5784c83ae86455a75a537a922b8f6c1c3 Mon Sep 17 00:00:00 2001 From: David Badura Date: Sun, 24 Dec 2023 11:31:14 +0100 Subject: [PATCH] rename handle to subscribe --- docs/pages/event_bus.md | 6 ++--- docs/pages/getting_started.md | 12 +++++----- docs/pages/processor.md | 4 ++-- docs/pages/projection.md | 8 +++---- src/Attribute/{Handle.php => Subscribe.php} | 2 +- ...ethod.php => DuplicateSubscribeMethod.php} | 4 ++-- src/EventBus/Subscriber.php | 20 ++++++++--------- .../AttributeProjectorMetadataFactory.php | 16 +++++++------- ...ethod.php => DuplicateSubscribeMethod.php} | 4 ++-- src/Metadata/Projector/ProjectorMetadata.php | 2 +- .../Projectionist/DefaultProjectionist.php | 6 ++--- .../Projector/MetadataProjectorResolver.php | 8 +++---- src/Projection/Projector/ProjectorHelper.php | 6 ++--- .../Projector/ProjectorResolver.php | 2 +- .../Processor/SendEmailProcessor.php | 4 ++-- .../Projection/ProfileProjector.php | 4 ++-- .../Projection/BankAccountProjection.php | 6 ++--- .../Processor/SendEmailProcessor.php | 4 ++-- .../Projection/ProfileProjection.php | 4 ++-- .../Outbox/Projection/ProfileProjection.php | 4 ++-- .../Projection/ProfileProjection.php | 4 ++-- tests/Unit/EventBus/SubscriberTest.php | 22 +++++++++---------- tests/Unit/Fixture/Dummy2Projection.php | 4 ++-- tests/Unit/Fixture/DummyProjection.php | 4 ++-- .../AttributeProjectorMetadataFactoryTest.php | 14 ++++++------ .../DefaultProjectionistTest.php | 12 +++++----- .../MetadataProjectorResolverTest.php | 8 +++---- .../Projector/ProjectorHelperTest.php | 6 ++--- 28 files changed, 100 insertions(+), 100 deletions(-) rename src/Attribute/{Handle.php => Subscribe.php} (94%) rename src/EventBus/{DuplicateHandleMethod.php => DuplicateSubscribeMethod.php} (80%) rename src/Metadata/Projector/{DuplicateHandleMethod.php => DuplicateSubscribeMethod.php} (83%) diff --git a/docs/pages/event_bus.md b/docs/pages/event_bus.md index 2b3ece9f..ed856a90 100644 --- a/docs/pages/event_bus.md +++ b/docs/pages/event_bus.md @@ -163,16 +163,16 @@ final class WelcomeListener implements Listener ## Subscriber A `Subscriber` is a listener, except that it has implemented the invoke method itself. -Instead, you can define your own and multiple methods and listen for specific events with the attribute `Handle`. +Instead, you can define your own and multiple methods and listen for specific events with the attribute `Subscribe`. ```php -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Listener; use Patchlevel\EventSourcing\EventBus\Message; final class WelcomeSubscriber extends Subscriber { - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function onProfileCreated(Message $message): void { echo 'Welcome!'; diff --git a/docs/pages/getting_started.md b/docs/pages/getting_started.md index 0b55593e..34392f30 100644 --- a/docs/pages/getting_started.md +++ b/docs/pages/getting_started.md @@ -156,7 +156,7 @@ Each projector is then responsible for a specific projection and version. use Doctrine\DBAL\Connection; use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -181,7 +181,7 @@ final class HotelProjection implements Projector return $this->db->fetchAllAssociative('SELECT id, name, guests FROM hotel;') } - #[Handle(HotelCreated::class)] + #[Subscribe(HotelCreated::class)] public function handleHotelCreated(Message $message): void { $event = $message->event(); @@ -196,7 +196,7 @@ final class HotelProjection implements Projector ); } - #[Handle(GuestIsCheckedIn::class)] + #[Subscribe(GuestIsCheckedIn::class)] public function handleGuestIsCheckedIn(Message $message): void { $this->db->executeStatement( @@ -205,7 +205,7 @@ final class HotelProjection implements Projector ); } - #[Handle(GuestIsCheckedOut::class)] + #[Subscribe(GuestIsCheckedOut::class)] public function handleGuestIsCheckedOut(Message $message): void { $this->db->executeStatement( @@ -237,7 +237,7 @@ final class HotelProjection implements Projector In our example we also want to send an email to the head office as soon as a guest is checked in. ```php -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\EventBus\Subscriber; @@ -248,7 +248,7 @@ final class SendCheckInEmailProcessor extends Subscriber ) { } - #[Handle(GuestIsCheckedIn::class)] + #[Subscribe(GuestIsCheckedIn::class)] public function onGuestIsCheckedIn(Message $message): void { $this->mailer->send( diff --git a/docs/pages/processor.md b/docs/pages/processor.md index 5d8d39dd..bbe94b55 100644 --- a/docs/pages/processor.md +++ b/docs/pages/processor.md @@ -50,7 +50,7 @@ final class SendEmailProcessor implements Listener You can also create the whole thing as a subscriber too. ```php -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\EventBus\Subscriber; @@ -61,7 +61,7 @@ final class SendEmailProcessor extends Subscriber ) { } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function onProfileCreated(Message $message): void { $this->mailer->send( diff --git a/docs/pages/projection.md b/docs/pages/projection.md index 6e7caa40..61065ef8 100644 --- a/docs/pages/projection.md +++ b/docs/pages/projection.md @@ -17,7 +17,7 @@ In this example we always create a new data set in a relational database when a use Doctrine\DBAL\Connection; use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -63,7 +63,7 @@ final class ProfileProjection implements Projector ); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(Message $message): void { $profileCreated = $message->event(); @@ -97,8 +97,8 @@ Projectors can have one `create` and `drop` method that is executed when the pro In some cases it may be that no schema has to be created for the projection, as the target does it automatically. To do this, you must add either the `Create` or `Drop` attribute to the method. The method name itself doesn't matter. -Otherwise, a projector can have any number of handle methods that are called for certain defined events. -In order to say which method is responsible for which event, you need the `Handle` attribute. +Otherwise, a projector can subscribe any number of events. +In order to say which method is responsible for which event, you need the `Subscribe` attribute. As the first parameter, you must pass the event class to which the reaction should then take place. The method itself must expect a `Message`, which then contains the event. The method name itself doesn't matter. diff --git a/src/Attribute/Handle.php b/src/Attribute/Subscribe.php similarity index 94% rename from src/Attribute/Handle.php rename to src/Attribute/Subscribe.php index 1c27d4f2..780c73dc 100644 --- a/src/Attribute/Handle.php +++ b/src/Attribute/Subscribe.php @@ -7,7 +7,7 @@ use Attribute; #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] -final class Handle +final class Subscribe { /** @param class-string $eventClass */ public function __construct( diff --git a/src/EventBus/DuplicateHandleMethod.php b/src/EventBus/DuplicateSubscribeMethod.php similarity index 80% rename from src/EventBus/DuplicateHandleMethod.php rename to src/EventBus/DuplicateSubscribeMethod.php index 693d5483..a2daaa0f 100644 --- a/src/EventBus/DuplicateHandleMethod.php +++ b/src/EventBus/DuplicateSubscribeMethod.php @@ -6,7 +6,7 @@ use function sprintf; -final class DuplicateHandleMethod extends EventBusException +final class DuplicateSubscribeMethod extends EventBusException { /** * @param class-string $subscriber @@ -16,7 +16,7 @@ public function __construct(string $subscriber, string $event, string $fistMetho { parent::__construct( sprintf( - 'Two methods "%s" and "%s" on the subscriber "%s" want to handle the same event "%s". Only one method can handle an event.', + 'Two methods "%s" and "%s" on the subscriber "%s" want to subscribe the same event "%s". Only one method can subscribe an event.', $fistMethod, $secondMethod, $subscriber, diff --git a/src/EventBus/Subscriber.php b/src/EventBus/Subscriber.php index aef3e6da..a1e02ceb 100644 --- a/src/EventBus/Subscriber.php +++ b/src/EventBus/Subscriber.php @@ -4,7 +4,7 @@ namespace Patchlevel\EventSourcing\EventBus; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use ReflectionClass; use function array_key_exists; @@ -12,15 +12,15 @@ abstract class Subscriber implements Listener { /** @var array|null */ - private array|null $handleMethods = null; + private array|null $subscribeMethods = null; final public function __invoke(Message $message): void { - if ($this->handleMethods === null) { + if ($this->subscribeMethods === null) { $this->init(); } - $method = $this->handleMethods[$message->event()::class] ?? null; + $method = $this->subscribeMethods[$message->event()::class] ?? null; if (!$method) { return; @@ -34,25 +34,25 @@ private function init(): void $reflection = new ReflectionClass(static::class); $methods = $reflection->getMethods(); - $this->handleMethods = []; + $this->subscribeMethods = []; foreach ($methods as $method) { - $attributes = $method->getAttributes(Handle::class); + $attributes = $method->getAttributes(Subscribe::class); foreach ($attributes as $attribute) { $instance = $attribute->newInstance(); $eventClass = $instance->eventClass(); - if (array_key_exists($eventClass, $this->handleMethods)) { - throw new DuplicateHandleMethod( + if (array_key_exists($eventClass, $this->subscribeMethods)) { + throw new DuplicateSubscribeMethod( static::class, $eventClass, - $this->handleMethods[$eventClass], + $this->subscribeMethods[$eventClass], $method->getName(), ); } - $this->handleMethods[$eventClass] = $method->getName(); + $this->subscribeMethods[$eventClass] = $method->getName(); } } } diff --git a/src/Metadata/Projector/AttributeProjectorMetadataFactory.php b/src/Metadata/Projector/AttributeProjectorMetadataFactory.php index 1d12d9ea..3e0e6529 100644 --- a/src/Metadata/Projector/AttributeProjectorMetadataFactory.php +++ b/src/Metadata/Projector/AttributeProjectorMetadataFactory.php @@ -6,7 +6,7 @@ use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\Projection\Projector\Projector; use ReflectionClass; @@ -28,27 +28,27 @@ public function metadata(string $projector): ProjectorMetadata $methods = $reflector->getMethods(); - $handleMethods = []; + $subscribeMethods = []; $createMethod = null; $dropMethod = null; foreach ($methods as $method) { - $attributes = $method->getAttributes(Handle::class); + $attributes = $method->getAttributes(Subscribe::class); foreach ($attributes as $attribute) { $instance = $attribute->newInstance(); $eventClass = $instance->eventClass(); - if (array_key_exists($eventClass, $handleMethods)) { - throw new DuplicateHandleMethod( + if (array_key_exists($eventClass, $subscribeMethods)) { + throw new DuplicateSubscribeMethod( $projector, $eventClass, - $handleMethods[$eventClass], + $subscribeMethods[$eventClass], $method->getName(), ); } - $handleMethods[$eventClass] = $method->getName(); + $subscribeMethods[$eventClass] = $method->getName(); } if ($method->getAttributes(Create::class)) { @@ -79,7 +79,7 @@ public function metadata(string $projector): ProjectorMetadata } $metadata = new ProjectorMetadata( - $handleMethods, + $subscribeMethods, $createMethod, $dropMethod, ); diff --git a/src/Metadata/Projector/DuplicateHandleMethod.php b/src/Metadata/Projector/DuplicateSubscribeMethod.php similarity index 83% rename from src/Metadata/Projector/DuplicateHandleMethod.php rename to src/Metadata/Projector/DuplicateSubscribeMethod.php index a25294a4..ff72e1a5 100644 --- a/src/Metadata/Projector/DuplicateHandleMethod.php +++ b/src/Metadata/Projector/DuplicateSubscribeMethod.php @@ -9,7 +9,7 @@ use function sprintf; -final class DuplicateHandleMethod extends MetadataException +final class DuplicateSubscribeMethod extends MetadataException { /** * @param class-string $projector @@ -19,7 +19,7 @@ public function __construct(string $projector, string $event, string $fistMethod { parent::__construct( sprintf( - 'Two methods "%s" and "%s" on the projection "%s" want to handle the same event "%s". Only one method can handle an event.', + 'Two methods "%s" and "%s" on the projection "%s" want to subscribe the same event "%s". Only one method can subscribe an event.', $fistMethod, $secondMethod, $projector, diff --git a/src/Metadata/Projector/ProjectorMetadata.php b/src/Metadata/Projector/ProjectorMetadata.php index 9ff45c95..c236a451 100644 --- a/src/Metadata/Projector/ProjectorMetadata.php +++ b/src/Metadata/Projector/ProjectorMetadata.php @@ -8,7 +8,7 @@ final class ProjectorMetadata { public function __construct( /** @var array */ - public readonly array $handleMethods = [], + public readonly array $subscribeMethods = [], public readonly string|null $createMethod = null, public readonly string|null $dropMethod = null, ) { diff --git a/src/Projection/Projectionist/DefaultProjectionist.php b/src/Projection/Projectionist/DefaultProjectionist.php index 48456bda..979bf136 100644 --- a/src/Projection/Projectionist/DefaultProjectionist.php +++ b/src/Projection/Projectionist/DefaultProjectionist.php @@ -376,11 +376,11 @@ private function handleMessage(Message $message, Projection $projection, bool $t throw ProjectorNotFound::forProjectionId($projection->id()); } - $handleMethod = $this->projectorResolver->resolveHandleMethod($projector, $message); + $subscribeMethod = $this->projectorResolver->resolveSubscribeMethod($projector, $message); - if ($handleMethod) { + if ($subscribeMethod) { try { - $handleMethod($message); + $subscribeMethod($message); $this->logger?->debug( sprintf( diff --git a/src/Projection/Projector/MetadataProjectorResolver.php b/src/Projection/Projector/MetadataProjectorResolver.php index c048592c..477381ad 100644 --- a/src/Projection/Projector/MetadataProjectorResolver.php +++ b/src/Projection/Projector/MetadataProjectorResolver.php @@ -42,17 +42,17 @@ public function resolveDropMethod(Projector $projector): Closure|null return $projector->$method(...); } - public function resolveHandleMethod(Projector $projector, Message $message): Closure|null + public function resolveSubscribeMethod(Projector $projector, Message $message): Closure|null { $event = $message->event(); $metadata = $this->metadataFactory->metadata($projector::class); - if (!array_key_exists($event::class, $metadata->handleMethods)) { + if (!array_key_exists($event::class, $metadata->subscribeMethods)) { return null; } - $handleMethod = $metadata->handleMethods[$event::class]; + $subscribeMethod = $metadata->subscribeMethods[$event::class]; - return $projector->$handleMethod(...); + return $projector->$subscribeMethod(...); } } diff --git a/src/Projection/Projector/ProjectorHelper.php b/src/Projection/Projector/ProjectorHelper.php index 6a449e33..98901ee5 100644 --- a/src/Projection/Projector/ProjectorHelper.php +++ b/src/Projection/Projector/ProjectorHelper.php @@ -16,13 +16,13 @@ public function __construct( public function handleMessage(Message $message, Projector ...$projectors): void { foreach ($projectors as $projector) { - $handleMethod = $this->projectorResolver->resolveHandleMethod($projector, $message); + $subscribeMethod = $this->projectorResolver->resolveSubscribeMethod($projector, $message); - if (!$handleMethod) { + if (!$subscribeMethod) { continue; } - $handleMethod($message); + $subscribeMethod($message); } } diff --git a/src/Projection/Projector/ProjectorResolver.php b/src/Projection/Projector/ProjectorResolver.php index d0670d98..bb990614 100644 --- a/src/Projection/Projector/ProjectorResolver.php +++ b/src/Projection/Projector/ProjectorResolver.php @@ -13,5 +13,5 @@ public function resolveCreateMethod(Projector $projector): Closure|null; public function resolveDropMethod(Projector $projector): Closure|null; - public function resolveHandleMethod(Projector $projector, Message $message): Closure|null; + public function resolveSubscribeMethod(Projector $projector, Message $message): Closure|null; } diff --git a/tests/Benchmark/BasicImplementation/Processor/SendEmailProcessor.php b/tests/Benchmark/BasicImplementation/Processor/SendEmailProcessor.php index 5a2ad8f0..9a83040c 100644 --- a/tests/Benchmark/BasicImplementation/Processor/SendEmailProcessor.php +++ b/tests/Benchmark/BasicImplementation/Processor/SendEmailProcessor.php @@ -4,7 +4,7 @@ namespace Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Processor; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\EventBus\Subscriber; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Events\ProfileCreated; @@ -12,7 +12,7 @@ final class SendEmailProcessor extends Subscriber { - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function onProfileCreated(Message $message): void { SendEmailMock::send(); diff --git a/tests/Benchmark/BasicImplementation/Projection/ProfileProjector.php b/tests/Benchmark/BasicImplementation/Projection/ProfileProjector.php index b6423672..4f73768f 100644 --- a/tests/Benchmark/BasicImplementation/Projection/ProfileProjector.php +++ b/tests/Benchmark/BasicImplementation/Projection/ProfileProjector.php @@ -7,7 +7,7 @@ use Doctrine\DBAL\Connection; use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -39,7 +39,7 @@ public function drop(): void $this->connection->executeStatement('DROP TABLE IF EXISTS projection_profile;'); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(Message $message): void { $profileCreated = $message->event(); diff --git a/tests/Integration/BankAccountSplitStream/Projection/BankAccountProjection.php b/tests/Integration/BankAccountSplitStream/Projection/BankAccountProjection.php index 02081efa..24fca1cf 100644 --- a/tests/Integration/BankAccountSplitStream/Projection/BankAccountProjection.php +++ b/tests/Integration/BankAccountSplitStream/Projection/BankAccountProjection.php @@ -8,7 +8,7 @@ use Doctrine\DBAL\Schema\Table; use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -45,7 +45,7 @@ public function drop(): void $this->connection->createSchemaManager()->dropTable('projection_bank_account'); } - #[Handle(BankAccountCreated::class)] + #[Subscribe(BankAccountCreated::class)] public function handleBankAccountCreated(Message $message): void { $event = $message->event(); @@ -59,7 +59,7 @@ public function handleBankAccountCreated(Message $message): void ); } - #[Handle(BalanceAdded::class)] + #[Subscribe(BalanceAdded::class)] public function handleBalanceAdded(Message $message): void { $event = $message->event(); diff --git a/tests/Integration/BasicImplementation/Processor/SendEmailProcessor.php b/tests/Integration/BasicImplementation/Processor/SendEmailProcessor.php index 77be8813..911ec7d8 100644 --- a/tests/Integration/BasicImplementation/Processor/SendEmailProcessor.php +++ b/tests/Integration/BasicImplementation/Processor/SendEmailProcessor.php @@ -4,7 +4,7 @@ namespace Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Processor; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\EventBus\Subscriber; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Events\ProfileCreated; @@ -12,7 +12,7 @@ final class SendEmailProcessor extends Subscriber { - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function onProfileCreated(Message $message): void { SendEmailMock::send(); diff --git a/tests/Integration/BasicImplementation/Projection/ProfileProjection.php b/tests/Integration/BasicImplementation/Projection/ProfileProjection.php index f5253320..c421ff72 100644 --- a/tests/Integration/BasicImplementation/Projection/ProfileProjection.php +++ b/tests/Integration/BasicImplementation/Projection/ProfileProjection.php @@ -8,7 +8,7 @@ use Doctrine\DBAL\Schema\Table; use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -45,7 +45,7 @@ public function drop(): void $this->connection->createSchemaManager()->dropTable('projection_profile'); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(Message $message): void { $profileCreated = $message->event(); diff --git a/tests/Integration/Outbox/Projection/ProfileProjection.php b/tests/Integration/Outbox/Projection/ProfileProjection.php index 4fedfe52..5bbdc89d 100644 --- a/tests/Integration/Outbox/Projection/ProfileProjection.php +++ b/tests/Integration/Outbox/Projection/ProfileProjection.php @@ -8,7 +8,7 @@ use Doctrine\DBAL\Schema\Table; use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -43,7 +43,7 @@ public function drop(): void $this->connection->createSchemaManager()->dropTable('projection_profile'); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(Message $message): void { $profileCreated = $message->event(); diff --git a/tests/Integration/Projectionist/Projection/ProfileProjection.php b/tests/Integration/Projectionist/Projection/ProfileProjection.php index ece3a875..02084c97 100644 --- a/tests/Integration/Projectionist/Projection/ProfileProjection.php +++ b/tests/Integration/Projectionist/Projection/ProfileProjection.php @@ -8,7 +8,7 @@ use Doctrine\DBAL\Schema\Table; use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -41,7 +41,7 @@ public function drop(): void $this->connection->createSchemaManager()->dropTable($this->tableName()); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(Message $message): void { $profileCreated = $message->event(); diff --git a/tests/Unit/EventBus/SubscriberTest.php b/tests/Unit/EventBus/SubscriberTest.php index 48a787eb..52131b6c 100644 --- a/tests/Unit/EventBus/SubscriberTest.php +++ b/tests/Unit/EventBus/SubscriberTest.php @@ -4,9 +4,9 @@ namespace Patchlevel\EventSourcing\Tests\Unit\EventBus; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; -use Patchlevel\EventSourcing\EventBus\DuplicateHandleMethod; +use Patchlevel\EventSourcing\EventBus\DuplicateSubscribeMethod; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\EventBus\Subscriber; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; @@ -23,7 +23,7 @@ public function testSubscribeEvent(): void $subscriber = new class extends Subscriber { public Message|null $message = null; - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handle(Message $message): void { $this->message = $message; @@ -48,7 +48,7 @@ public function testSubscribeWrongEvent(): void $subscriber = new class extends Subscriber { public Message|null $message = null; - #[Handle(ProfileVisited::class)] + #[Subscribe(ProfileVisited::class)] public function handle(Message $message): void { $this->message = $message; @@ -74,13 +74,13 @@ public function testSubscribeMultipleEvents(): void public Message|null $a = null; public Message|null $b = null; - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleA(Message $message): void { $this->a = $message; } - #[Handle(ProfileVisited::class)] + #[Subscribe(ProfileVisited::class)] public function handleB(Message $message): void { $this->b = $message; @@ -113,8 +113,8 @@ public function testSubscribeMultipleEventsOnSameMethod(): void /** @var list */ public array $messages = []; - #[Handle(ProfileCreated::class)] - #[Handle(ProfileVisited::class)] + #[Subscribe(ProfileCreated::class)] + #[Subscribe(ProfileVisited::class)] public function handle(Message $message): void { $this->messages[] = $message; @@ -144,15 +144,15 @@ public function handle(Message $message): void public function testDuplicatedEvents(): void { - $this->expectException(DuplicateHandleMethod::class); + $this->expectException(DuplicateSubscribeMethod::class); $subscriber = new class extends Subscriber { - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleA(Message $message): void { } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleB(Message $message): void { } diff --git a/tests/Unit/Fixture/Dummy2Projection.php b/tests/Unit/Fixture/Dummy2Projection.php index 9d23ede3..036a6ccd 100644 --- a/tests/Unit/Fixture/Dummy2Projection.php +++ b/tests/Unit/Fixture/Dummy2Projection.php @@ -6,7 +6,7 @@ use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message as EventMessage; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -22,7 +22,7 @@ public function targetProjection(): ProjectionId return new ProjectionId('dummy2', 1); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(EventMessage $message): void { $this->handledMessage = $message; diff --git a/tests/Unit/Fixture/DummyProjection.php b/tests/Unit/Fixture/DummyProjection.php index 88ca60e4..dcc76b35 100644 --- a/tests/Unit/Fixture/DummyProjection.php +++ b/tests/Unit/Fixture/DummyProjection.php @@ -6,7 +6,7 @@ use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message as EventMessage; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -22,7 +22,7 @@ public function targetProjection(): ProjectionId return new ProjectionId('dummy', 1); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(EventMessage $message): void { $this->handledMessage = $message; diff --git a/tests/Unit/Metadata/Projector/AttributeProjectorMetadataFactoryTest.php b/tests/Unit/Metadata/Projector/AttributeProjectorMetadataFactoryTest.php index eb2d9d00..bfec4d5e 100644 --- a/tests/Unit/Metadata/Projector/AttributeProjectorMetadataFactoryTest.php +++ b/tests/Unit/Metadata/Projector/AttributeProjectorMetadataFactoryTest.php @@ -6,7 +6,7 @@ use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\Metadata\Projector\AttributeProjectorMetadataFactory; use Patchlevel\EventSourcing\Metadata\Projector\DuplicateCreateMethod; use Patchlevel\EventSourcing\Metadata\Projector\DuplicateDropMethod; @@ -30,7 +30,7 @@ public function targetProjection(): ProjectionId $metadataFactory = new AttributeProjectorMetadataFactory(); $metadata = $metadataFactory->metadata($projection::class); - self::assertSame([], $metadata->handleMethods); + self::assertSame([], $metadata->subscribeMethods); self::assertNull($metadata->createMethod); self::assertNull($metadata->dropMethod); } @@ -43,7 +43,7 @@ public function targetProjection(): ProjectionId return new ProjectionId('foo', 1); } - #[Handle(ProfileVisited::class)] + #[Subscribe(ProfileVisited::class)] public function handle(): void { } @@ -64,7 +64,7 @@ public function drop(): void self::assertEquals( [ProfileVisited::class => 'handle'], - $metadata->handleMethods, + $metadata->subscribeMethods, ); self::assertSame('create', $metadata->createMethod); @@ -79,8 +79,8 @@ public function targetProjection(): ProjectionId return new ProjectionId('foo', 1); } - #[Handle(ProfileVisited::class)] - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileVisited::class)] + #[Subscribe(ProfileCreated::class)] public function handle(): void { } @@ -94,7 +94,7 @@ public function handle(): void ProfileVisited::class => 'handle', ProfileCreated::class => 'handle', ], - $metadata->handleMethods, + $metadata->subscribeMethods, ); } diff --git a/tests/Unit/Projection/Projectionist/DefaultProjectionistTest.php b/tests/Unit/Projection/Projectionist/DefaultProjectionistTest.php index 2ea96a25..50b0a16f 100644 --- a/tests/Unit/Projection/Projectionist/DefaultProjectionistTest.php +++ b/tests/Unit/Projection/Projectionist/DefaultProjectionistTest.php @@ -129,7 +129,7 @@ public function handle(Message $message): void $projectorResolver = $this->prophesize(ProjectorResolver::class); $projectorResolver->resolveCreateMethod($projector)->willReturn($projector->create(...)); - $projectorResolver->resolveHandleMethod($projector, $message)->willReturn($projector->handle(...)); + $projectorResolver->resolveSubscribeMethod($projector, $message)->willReturn($projector->handle(...)); $projectionist = new DefaultProjectionist( $streamableStore->reveal(), @@ -184,7 +184,7 @@ public function handle(Message $message): void $projectorResolver = $this->prophesize(ProjectorResolver::class); $projectorResolver->resolveCreateMethod($projector)->willReturn($projector->create(...)); - $projectorResolver->resolveHandleMethod($projector, $message)->willReturn($projector->handle(...)); + $projectorResolver->resolveSubscribeMethod($projector, $message)->willReturn($projector->handle(...)); $projectionist = new DefaultProjectionist( $streamableStore->reveal(), @@ -290,7 +290,7 @@ public function handle(Message $message): void $projectorRepository->projectors()->willReturn([$projector])->shouldBeCalledOnce(); $projectorResolver = $this->prophesize(ProjectorResolver::class); - $projectorResolver->resolveHandleMethod($projector, $message)->willReturn($projector->handle(...)); + $projectorResolver->resolveSubscribeMethod($projector, $message)->willReturn($projector->handle(...)); $projectionist = new DefaultProjectionist( $streamableStore->reveal(), @@ -339,7 +339,7 @@ public function handle(Message $message): void $projectorRepository->projectors()->willReturn([$projector])->shouldBeCalledOnce(); $projectorResolver = $this->prophesize(ProjectorResolver::class); - $projectorResolver->resolveHandleMethod($projector, $message1)->willReturn($projector->handle(...)); + $projectorResolver->resolveSubscribeMethod($projector, $message1)->willReturn($projector->handle(...)); $projectionist = new DefaultProjectionist( $streamableStore->reveal(), @@ -401,7 +401,7 @@ public function handle(Message $message): void $projectorRepository->projectors()->willReturn([$projector1, $projector2])->shouldBeCalledOnce(); $projectorResolver = $this->prophesize(ProjectorResolver::class); - $projectorResolver->resolveHandleMethod($projector1, $message)->willReturn($projector1->handle(...)); + $projectorResolver->resolveSubscribeMethod($projector1, $message)->willReturn($projector1->handle(...)); $projectionist = new DefaultProjectionist( $streamableStore->reveal(), @@ -450,7 +450,7 @@ public function handle(Message $message): void $projectorRepository->projectors()->willReturn([$projector])->shouldBeCalledOnce(); $projectorResolver = $this->prophesize(ProjectorResolver::class); - $projectorResolver->resolveHandleMethod($projector, $message)->willReturn($projector->handle(...)); + $projectorResolver->resolveSubscribeMethod($projector, $message)->willReturn($projector->handle(...)); $projectionist = new DefaultProjectionist( $streamableStore->reveal(), diff --git a/tests/Unit/Projection/Projector/MetadataProjectorResolverTest.php b/tests/Unit/Projection/Projector/MetadataProjectorResolverTest.php index 2f9535d9..ff941628 100644 --- a/tests/Unit/Projection/Projector/MetadataProjectorResolverTest.php +++ b/tests/Unit/Projection/Projector/MetadataProjectorResolverTest.php @@ -6,7 +6,7 @@ use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\MetadataProjectorResolver; @@ -30,7 +30,7 @@ public function targetProjection(): ProjectionId return new ProjectionId('dummy', 1); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(Message $message): void { self::$handledMessage = $message; @@ -45,7 +45,7 @@ public function handleProfileCreated(Message $message): void ); $resolver = new MetadataProjectorResolver(); - $result = $resolver->resolveHandleMethod($projection, $message); + $result = $resolver->resolveSubscribeMethod($projection, $message); self::assertIsCallable($result); @@ -70,7 +70,7 @@ public function targetProjection(): ProjectionId ); $resolver = new MetadataProjectorResolver(); - $result = $resolver->resolveHandleMethod($projection, $message); + $result = $resolver->resolveSubscribeMethod($projection, $message); self::assertNull($result); } diff --git a/tests/Unit/Projection/Projector/ProjectorHelperTest.php b/tests/Unit/Projection/Projector/ProjectorHelperTest.php index c73146d9..257bfb23 100644 --- a/tests/Unit/Projection/Projector/ProjectorHelperTest.php +++ b/tests/Unit/Projection/Projector/ProjectorHelperTest.php @@ -6,7 +6,7 @@ use Patchlevel\EventSourcing\Attribute\Create; use Patchlevel\EventSourcing\Attribute\Drop; -use Patchlevel\EventSourcing\Attribute\Handle; +use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Projection\Projection\ProjectionId; use Patchlevel\EventSourcing\Projection\Projector\Projector; @@ -30,7 +30,7 @@ public function targetProjection(): ProjectionId return new ProjectionId('dummy', 1); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(Message $message): void { self::$handledMessage = $message; @@ -62,7 +62,7 @@ public function targetProjection(): ProjectionId return new ProjectionId('dummy', 1); } - #[Handle(ProfileCreated::class)] + #[Subscribe(ProfileCreated::class)] public function handleProfileCreated(Message $message): void { self::$handledMessage = $message;