diff --git a/docs/pages/getting_started.md b/docs/pages/getting_started.md index 7c3bf5559..c886aad16 100644 --- a/docs/pages/getting_started.md +++ b/docs/pages/getting_started.md @@ -154,18 +154,18 @@ final class Hotel extends BasicAggregateRoot So that we can see all the hotels on our website and also see how many guests are currently visiting the hotels, we need a projection for it. To create a projection we need a projector. -Each subscriber is then responsible for a specific projection. +Each projector is then responsible for a specific projection. ```php use Doctrine\DBAL\Connection; +use Patchlevel\EventSourcing\Attribute\Projector; use Patchlevel\EventSourcing\Attribute\Setup; -use Patchlevel\EventSourcing\Attribute\Teardown; use Patchlevel\EventSourcing\Attribute\Subscribe; -use Patchlevel\EventSourcing\Attribute\Subscriber; +use Patchlevel\EventSourcing\Attribute\Teardown; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberUtil; -#[Subscriber('hotel')] +#[Projector('hotel')] final class HotelProjector { use SubscriberUtil; @@ -237,17 +237,18 @@ final class HotelProjector !!! note - You can find out more about subscriptions [here](subscription.md). + You can find out more about projector [here](subscription.md). ## Processor In our example we also want to email the head office as soon as a guest is checked in. ```php +use Patchlevel\EventSourcing\Attribute\Processor; use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\EventBus\Message; -use Patchlevel\EventSourcing\EventBus\Subscriber; +#[Processor('admin_emails')] final class SendCheckInEmailProcessor { public function __construct( @@ -308,6 +309,7 @@ $hotelProjector = new HotelProjector($projectionConnection); $projectorRepository = new MetadataSubscriberAccessorRepository([ $hotelProjector, + new SendCheckInEmailProcessor($mailer), ]); $projectionStore = new DoctrineSubscriptionStore($connection); @@ -318,9 +320,7 @@ $projectionist = new DefaultSubscriptionEngine( $projectorRepository, ); -$eventBus = DefaultEventBus::create([ - new SendCheckInEmailProcessor($mailer), -]); +$eventBus = DefaultEventBus::create(); $repositoryManager = new DefaultRepositoryManager( $aggregateRegistry, diff --git a/docs/pages/subscription.md b/docs/pages/subscription.md index bbf3b1809..9491a6c63 100644 --- a/docs/pages/subscription.md +++ b/docs/pages/subscription.md @@ -19,7 +19,7 @@ use Doctrine\DBAL\Connection; use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberUtil; -#[Subscriber('profile_1')] +#[Subscriber('profile_1', RunMode::FromBeginning)] final class ProfileSubscriber { use SubscriberUtil; diff --git a/src/Attribute/Processor.php b/src/Attribute/Processor.php new file mode 100644 index 000000000..d79af61df --- /dev/null +++ b/src/Attribute/Processor.php @@ -0,0 +1,20 @@ +getAttributes(Subscriber::class); + $attributes = $reflector->getAttributes(Subscriber::class, ReflectionAttribute::IS_INSTANCEOF); if ($attributes === []) { throw new ClassIsNotASubscriber($subscriber); diff --git a/tests/Benchmark/BasicImplementation/Processor/SendEmailProcessor.php b/tests/Benchmark/BasicImplementation/Processor/SendEmailProcessor.php index 7c583f203..c0cc59ae5 100644 --- a/tests/Benchmark/BasicImplementation/Processor/SendEmailProcessor.php +++ b/tests/Benchmark/BasicImplementation/Processor/SendEmailProcessor.php @@ -4,13 +4,13 @@ namespace Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Processor; +use Patchlevel\EventSourcing\Attribute\Processor; use Patchlevel\EventSourcing\Attribute\Subscribe; -use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Events\ProfileCreated; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\SendEmailMock; -#[Subscriber('send_email')] +#[Processor('send_email')] final class SendEmailProcessor { #[Subscribe(ProfileCreated::class)] diff --git a/tests/Benchmark/BasicImplementation/Projection/ProfileProjector.php b/tests/Benchmark/BasicImplementation/Projection/ProfileProjector.php index fac643d87..4b060cb07 100644 --- a/tests/Benchmark/BasicImplementation/Projection/ProfileProjector.php +++ b/tests/Benchmark/BasicImplementation/Projection/ProfileProjector.php @@ -6,9 +6,9 @@ use Doctrine\DBAL\Connection; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; +use Patchlevel\EventSourcing\Attribute\Projector; use Patchlevel\EventSourcing\Attribute\Setup; use Patchlevel\EventSourcing\Attribute\Subscribe; -use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\Attribute\Teardown; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberUtil; @@ -17,7 +17,7 @@ use function assert; -#[Subscriber('profile')] +#[Projector('profile')] final class ProfileProjector { use SubscriberUtil; diff --git a/tests/Integration/BankAccountSplitStream/Projection/BankAccountProjector.php b/tests/Integration/BankAccountSplitStream/Projection/BankAccountProjector.php index 64f7da905..310610db2 100644 --- a/tests/Integration/BankAccountSplitStream/Projection/BankAccountProjector.php +++ b/tests/Integration/BankAccountSplitStream/Projection/BankAccountProjector.php @@ -6,9 +6,9 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\Table; +use Patchlevel\EventSourcing\Attribute\Projector; use Patchlevel\EventSourcing\Attribute\Setup; use Patchlevel\EventSourcing\Attribute\Subscribe; -use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\Attribute\Teardown; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Tests\Integration\BankAccountSplitStream\Events\BalanceAdded; @@ -16,7 +16,7 @@ use function assert; -#[Subscriber('dummy-1')] +#[Projector('dummy-1')] final class BankAccountProjector { public function __construct( diff --git a/tests/Integration/BasicImplementation/Projection/ProfileProjector.php b/tests/Integration/BasicImplementation/Projection/ProfileProjector.php index 5203d4b52..7913679cf 100644 --- a/tests/Integration/BasicImplementation/Projection/ProfileProjector.php +++ b/tests/Integration/BasicImplementation/Projection/ProfileProjector.php @@ -6,16 +6,16 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\Table; +use Patchlevel\EventSourcing\Attribute\Projector; use Patchlevel\EventSourcing\Attribute\Setup; use Patchlevel\EventSourcing\Attribute\Subscribe; -use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\Attribute\Teardown; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Events\ProfileCreated; use function assert; -#[Subscriber('profile-1')] +#[Projector('profile-1')] final class ProfileProjector { public function __construct( diff --git a/tests/Integration/Subscription/Subscriber/ErrorProducerSubscriber.php b/tests/Integration/Subscription/Subscriber/ErrorProducerSubscriber.php index 2fab5b205..d7c554b97 100644 --- a/tests/Integration/Subscription/Subscriber/ErrorProducerSubscriber.php +++ b/tests/Integration/Subscription/Subscriber/ErrorProducerSubscriber.php @@ -9,9 +9,10 @@ use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\Attribute\Teardown; use Patchlevel\EventSourcing\EventBus\Message; +use Patchlevel\EventSourcing\Subscription\RunMode; use RuntimeException; -#[Subscriber('error_producer')] +#[Subscriber('error_producer', RunMode::FromBeginning)] final class ErrorProducerSubscriber { public bool $setupError = false; diff --git a/tests/Integration/Subscription/Subscriber/ProfileProcessor.php b/tests/Integration/Subscription/Subscriber/ProfileProcessor.php index c017389ab..71bb63e14 100644 --- a/tests/Integration/Subscription/Subscriber/ProfileProcessor.php +++ b/tests/Integration/Subscription/Subscriber/ProfileProcessor.php @@ -4,8 +4,8 @@ namespace Patchlevel\EventSourcing\Tests\Integration\Subscription\Subscriber; +use Patchlevel\EventSourcing\Attribute\Processor; use Patchlevel\EventSourcing\Attribute\Subscribe; -use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Repository\RepositoryManager; use Patchlevel\EventSourcing\Tests\Integration\Subscription\Aggregate\Profile; @@ -13,7 +13,7 @@ use function assert; -#[Subscriber('profile')] +#[Processor('profile')] final class ProfileProcessor { public function __construct( diff --git a/tests/Integration/Subscription/Subscriber/ProfileProjection.php b/tests/Integration/Subscription/Subscriber/ProfileProjection.php index a55032651..8e576ea64 100644 --- a/tests/Integration/Subscription/Subscriber/ProfileProjection.php +++ b/tests/Integration/Subscription/Subscriber/ProfileProjection.php @@ -6,9 +6,9 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\Table; +use Patchlevel\EventSourcing\Attribute\Projector; use Patchlevel\EventSourcing\Attribute\Setup; use Patchlevel\EventSourcing\Attribute\Subscribe; -use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\Attribute\Teardown; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberUtil; @@ -16,7 +16,7 @@ use function assert; -#[Subscriber('profile_1')] +#[Projector('profile_1')] final class ProfileProjection { use SubscriberUtil; diff --git a/tests/Integration/Subscription/SubscriptionTest.php b/tests/Integration/Subscription/SubscriptionTest.php index b386a3f02..e813964b6 100644 --- a/tests/Integration/Subscription/SubscriptionTest.php +++ b/tests/Integration/Subscription/SubscriptionTest.php @@ -99,7 +99,13 @@ public function testHappyPath(): void ); self::assertEquals( - [new Subscription('profile_1', lastSavedAt: new DateTimeImmutable('2021-01-01T00:00:00'))], + [ + new Subscription( + 'profile_1', + 'projector', + lastSavedAt: new DateTimeImmutable('2021-01-01T00:00:00'), + ), + ], $engine->subscriptions(), ); @@ -109,7 +115,7 @@ public function testHappyPath(): void [ new Subscription( 'profile_1', - Subscription::DEFAULT_GROUP, + 'projector', RunMode::FromBeginning, Status::Active, lastSavedAt: new DateTimeImmutable('2021-01-01T00:00:00'), @@ -127,7 +133,7 @@ public function testHappyPath(): void [ new Subscription( 'profile_1', - Subscription::DEFAULT_GROUP, + 'projector', RunMode::FromBeginning, Status::Active, 1, @@ -153,7 +159,7 @@ public function testHappyPath(): void [ new Subscription( 'profile_1', - Subscription::DEFAULT_GROUP, + 'projector', RunMode::FromBeginning, Status::New, lastSavedAt: new DateTimeImmutable('2021-01-01T00:00:00'), @@ -354,7 +360,14 @@ public function testProcessor(): void ); self::assertEquals( - [new Subscription('profile', lastSavedAt: new DateTimeImmutable('2021-01-01T00:00:00'))], + [ + new Subscription( + 'profile', + 'processor', + RunMode::FromNow, + lastSavedAt: new DateTimeImmutable('2021-01-01T00:00:00'), + ), + ], $engine->subscriptions(), ); @@ -364,8 +377,8 @@ public function testProcessor(): void [ new Subscription( 'profile', - Subscription::DEFAULT_GROUP, - RunMode::FromBeginning, + 'processor', + RunMode::FromNow, Status::Active, lastSavedAt: new DateTimeImmutable('2021-01-01T00:00:00'), ), @@ -399,7 +412,7 @@ public function testProcessor(): void new TraceHeader([ [ 'name' => 'profile', - 'category' => 'event_sourcing/subscriber/default', + 'category' => 'event_sourcing/subscriber/processor', ], ]), $messages[1]->header(TraceHeader::class), diff --git a/tests/Unit/Attribute/SubscriberTest.php b/tests/Unit/Attribute/SubscriberTest.php index fb14ed72a..fcbf24b99 100644 --- a/tests/Unit/Attribute/SubscriberTest.php +++ b/tests/Unit/Attribute/SubscriberTest.php @@ -5,6 +5,7 @@ namespace Patchlevel\EventSourcing\Tests\Unit\Attribute; use Patchlevel\EventSourcing\Attribute\Subscriber; +use Patchlevel\EventSourcing\Subscription\RunMode; use PHPUnit\Framework\TestCase; /** @covers \Patchlevel\EventSourcing\Attribute\Subscriber */ @@ -12,7 +13,7 @@ final class SubscriberTest extends TestCase { public function testInstantiate(): void { - $attribute = new Subscriber('foo'); + $attribute = new Subscriber('foo', RunMode::FromBeginning); self::assertSame('foo', $attribute->id); } diff --git a/tests/Unit/Fixture/Dummy2Subscriber.php b/tests/Unit/Fixture/Dummy2Subscriber.php deleted file mode 100644 index 032e96b36..000000000 --- a/tests/Unit/Fixture/Dummy2Subscriber.php +++ /dev/null @@ -1,37 +0,0 @@ -handledMessage = $message; - } - - #[Setup] - public function create(): void - { - $this->createCalled = true; - } - - #[Teardown] - public function drop(): void - { - $this->dropCalled = true; - } -} diff --git a/tests/Unit/Fixture/DummySubscriber.php b/tests/Unit/Fixture/DummySubscriber.php deleted file mode 100644 index da5fa71c3..000000000 --- a/tests/Unit/Fixture/DummySubscriber.php +++ /dev/null @@ -1,37 +0,0 @@ -handledMessage = $message; - } - - #[Setup] - public function create(): void - { - $this->createCalled = true; - } - - #[Teardown] - public function drop(): void - { - $this->dropCalled = true; - } -} diff --git a/tests/Unit/Metadata/Subscriber/AttributeSubscriberMetadataFactoryTest.php b/tests/Unit/Metadata/Subscriber/AttributeSubscriberMetadataFactoryTest.php index 379509630..770e8bb97 100644 --- a/tests/Unit/Metadata/Subscriber/AttributeSubscriberMetadataFactoryTest.php +++ b/tests/Unit/Metadata/Subscriber/AttributeSubscriberMetadataFactoryTest.php @@ -4,6 +4,8 @@ namespace Patchlevel\EventSourcing\Tests\Unit\Metadata\Subscriber; +use Patchlevel\EventSourcing\Attribute\Processor; +use Patchlevel\EventSourcing\Attribute\Projector; use Patchlevel\EventSourcing\Attribute\Setup; use Patchlevel\EventSourcing\Attribute\Subscribe; use Patchlevel\EventSourcing\Attribute\Subscriber; @@ -12,6 +14,7 @@ use Patchlevel\EventSourcing\Metadata\Subscriber\ClassIsNotASubscriber; use Patchlevel\EventSourcing\Metadata\Subscriber\DuplicateSetupMethod; use Patchlevel\EventSourcing\Metadata\Subscriber\DuplicateTeardownMethod; +use Patchlevel\EventSourcing\Subscription\RunMode; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; use PHPUnit\Framework\TestCase; @@ -32,7 +35,7 @@ public function testNotASubscriber(): void public function testEmptySubscriber(): void { - $subscriber = new #[Subscriber('foo')] + $subscriber = new #[Subscriber('foo', RunMode::FromBeginning)] class { }; @@ -45,9 +48,43 @@ class { self::assertSame('foo', $metadata->id); } + public function testProjector(): void + { + $subscriber = new #[Projector('foo')] + class { + }; + + $metadataFactory = new AttributeSubscriberMetadataFactory(); + $metadata = $metadataFactory->metadata($subscriber::class); + + self::assertSame([], $metadata->subscribeMethods); + self::assertNull($metadata->setupMethod); + self::assertNull($metadata->teardownMethod); + self::assertSame('foo', $metadata->id); + self::assertSame('projector', $metadata->group); + self::assertSame(RunMode::FromBeginning, $metadata->runMode); + } + + public function testProcessor(): void + { + $subscriber = new #[Processor('foo')] + class { + }; + + $metadataFactory = new AttributeSubscriberMetadataFactory(); + $metadata = $metadataFactory->metadata($subscriber::class); + + self::assertSame([], $metadata->subscribeMethods); + self::assertNull($metadata->setupMethod); + self::assertNull($metadata->teardownMethod); + self::assertSame('foo', $metadata->id); + self::assertSame('processor', $metadata->group); + self::assertSame(RunMode::FromNow, $metadata->runMode); + } + public function testStandardSubscriber(): void { - $subscriber = new #[Subscriber('foo')] + $subscriber = new #[Subscriber('foo', RunMode::FromBeginning)] class { #[Subscribe(ProfileVisited::class)] public function handle(): void @@ -79,7 +116,7 @@ public function drop(): void public function testMultipleHandlerOnOneMethod(): void { - $subscriber = new #[Subscriber('foo')] + $subscriber = new #[Subscriber('foo', RunMode::FromBeginning)] class { #[Subscribe(ProfileVisited::class)] #[Subscribe(ProfileCreated::class)] @@ -102,7 +139,7 @@ public function handle(): void public function testSubscribeAll(): void { - $subscriber = new #[Subscriber('foo')] + $subscriber = new #[Subscriber('foo', RunMode::FromBeginning)] class { #[Subscribe(Subscribe::ALL)] public function handle(): void @@ -125,7 +162,7 @@ public function testDuplicateSetupAttributeException(): void { $this->expectException(DuplicateSetupMethod::class); - $subscriber = new #[Subscriber('foo')] + $subscriber = new #[Subscriber('foo', RunMode::FromBeginning)] class { #[Setup] public function create1(): void @@ -146,7 +183,7 @@ public function testDuplicateTeardownAttributeException(): void { $this->expectException(DuplicateTeardownMethod::class); - $subscriber = new #[Subscriber('foo')] + $subscriber = new #[Subscriber('foo', RunMode::FromBeginning)] class { #[Teardown] public function drop1(): void diff --git a/tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php b/tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php index 67e85b3b1..bf2b36ad2 100644 --- a/tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php +++ b/tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php @@ -62,7 +62,7 @@ public function testNothingToBoot(): void public function testBootDiscoverNewSubscribers(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -107,7 +107,7 @@ class { public function testBootWithoutCreateMethod(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -155,7 +155,7 @@ class { public function testBootWithMethods(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public Message|null $message = null; public bool $created = false; @@ -227,7 +227,7 @@ public function handle(Message $message): void public function testBootWithLimit(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public Message|null $message = null; public bool $created = false; @@ -292,7 +292,7 @@ public function handle(Message $message): void public function testBootingWithSkip(): void { $subscriptionId1 = 'test1'; - $subscriber1 = new #[Subscriber('test1')] + $subscriber1 = new #[Subscriber('test1', RunMode::FromBeginning)] class { public Message|null $message = null; @@ -304,7 +304,7 @@ public function handle(Message $message): void }; $subscriptionId2 = 'test2'; - $subscriber2 = new #[Subscriber('test2')] + $subscriber2 = new #[Subscriber('test2', RunMode::FromBeginning)] class { public Message|null $message = null; @@ -382,7 +382,7 @@ public function handle(Message $message): void public function testBootWithCreateError(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public function __construct( public readonly RuntimeException $exception = new RuntimeException('ERROR'), @@ -433,7 +433,7 @@ public function create(): void public function testBootingWithGabInIndex(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { /** @var list */ public array $messages = []; @@ -491,7 +491,7 @@ public function handle(Message $message): void public function testBootingWithFromNow(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test', runMode: RunMode::FromNow)] + $subscriber = new #[Subscriber('test', RunMode::FromNow)] class { public Message|null $message = null; @@ -540,7 +540,7 @@ public function handle(Message $message): void public function testBootingWithFromNowWithEmtpyStream(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test', runMode: RunMode::FromNow)] + $subscriber = new #[Subscriber('test', RunMode::FromNow)] class { public Message|null $message = null; @@ -589,7 +589,7 @@ public function handle(Message $message): void public function testBootingWithOnlyOnce(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test', runMode: RunMode::Once)] + $subscriber = new #[Subscriber('test', RunMode::Once)] class { public Message|null $message = null; @@ -645,7 +645,7 @@ public function handle(Message $message): void public function testRunDiscoverNewSubscribers(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -673,7 +673,7 @@ class { public function testRunning(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public Message|null $message = null; @@ -722,7 +722,7 @@ public function handle(Message $message): void public function testRunningWithLimit(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public Message|null $message = null; @@ -775,7 +775,7 @@ public function handle(Message $message): void public function testRunningWithSkip(): void { $subscriptionId1 = 'test1'; - $subscriber1 = new #[Subscriber('test1')] + $subscriber1 = new #[Subscriber('test1', RunMode::FromBeginning)] class { public Message|null $message = null; @@ -787,7 +787,7 @@ public function handle(Message $message): void }; $subscriptionId2 = 'test2'; - $subscriber2 = new #[Subscriber('test2')] + $subscriber2 = new #[Subscriber('test2', RunMode::FromBeginning)] class { public Message|null $message = null; @@ -851,7 +851,7 @@ public function handle(Message $message): void public function testRunningWithError(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public function __construct( public readonly RuntimeException $exception = new RuntimeException('ERROR'), @@ -971,7 +971,7 @@ public function testRunningWithoutActiveSubscribers(): void public function testRunningWithGabInIndex(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { /** @var list */ public array $messages = []; @@ -1022,7 +1022,7 @@ public function handle(Message $message): void public function testTeardownDiscoverNewSubscribers(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1050,7 +1050,7 @@ class { public function testTeardownWithoutTeardownMethod(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1080,7 +1080,7 @@ class { public function testTeardownWithSubscriber(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public Message|null $message = null; public bool $dropped = false; @@ -1119,7 +1119,7 @@ public function drop(): void public function testTeardownWithSubscriberAndError(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public Message|null $message = null; public bool $dropped = false; @@ -1184,7 +1184,7 @@ public function testTeardownWithoutSubscriber(): void public function testRemoveDiscoverNewSubscribers(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1212,7 +1212,7 @@ class { public function testRemoveWithSubscriber(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public bool $dropped = false; @@ -1249,7 +1249,7 @@ public function drop(): void public function testRemoveWithoutDropMethod(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1278,7 +1278,7 @@ class { public function testRemoveWithSubscriberAndError(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { public bool $dropped = false; @@ -1340,7 +1340,7 @@ public function testRemoveWithoutSubscriber(): void public function testReactiveDiscoverNewSubscribers(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1368,7 +1368,7 @@ class { public function testReactivateError(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1407,7 +1407,7 @@ class { public function testReactivateOutdated(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1443,7 +1443,7 @@ class { public function testReactivatePaused(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1479,7 +1479,7 @@ class { public function testReactivateFinished(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1515,7 +1515,7 @@ class { public function testPauseDiscoverNewSubscribers(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1543,7 +1543,7 @@ class { public function testPauseBooting(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1579,7 +1579,7 @@ class { public function testPauseActive(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1615,7 +1615,7 @@ class { public function testPauseError(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1655,7 +1655,7 @@ class { public function testGetSubscriptionAndDiscoverNewSubscribers(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1692,7 +1692,7 @@ class { public function testRetry(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { #[Subscribe(ProfileVisited::class)] public function subscribe(): void @@ -1752,7 +1752,7 @@ public function subscribe(): void public function testShouldNotRetry(): void { $subscriptionId = 'test'; - $subscriber = new #[Subscriber('test')] + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] class { }; @@ -1787,7 +1787,7 @@ class { #[DataProvider('methodProvider')] public function testCriteria(string $method): void { - $subscriber = new #[Subscriber('id1')] + $subscriber = new #[Subscriber('id1', RunMode::FromBeginning)] class { }; @@ -1824,7 +1824,7 @@ class { #[DataProvider('methodProvider')] public function testWithLockableStore(string $method): void { - $subscriber = new #[Subscriber('id1')] + $subscriber = new #[Subscriber('id1', RunMode::FromNow)] class { }; diff --git a/tests/Unit/Subscription/Subscriber/MetadataSubscriberAccessorRepositoryTest.php b/tests/Unit/Subscription/Subscriber/MetadataSubscriberAccessorRepositoryTest.php index d371b5018..160cb902c 100644 --- a/tests/Unit/Subscription/Subscriber/MetadataSubscriberAccessorRepositoryTest.php +++ b/tests/Unit/Subscription/Subscriber/MetadataSubscriberAccessorRepositoryTest.php @@ -6,6 +6,7 @@ use Patchlevel\EventSourcing\Attribute\Subscriber; use Patchlevel\EventSourcing\Metadata\Subscriber\AttributeSubscriberMetadataFactory; +use Patchlevel\EventSourcing\Subscription\RunMode; use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessor; use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository; use PHPUnit\Framework\TestCase; @@ -25,7 +26,7 @@ public function testEmpty(): void public function testWithSubscriber(): void { - $subscriber = new #[Subscriber('foo')] + $subscriber = new #[Subscriber('foo', RunMode::FromBeginning)] class { }; $metadataFactory = new AttributeSubscriberMetadataFactory(); diff --git a/tests/Unit/Subscription/Subscriber/MetadataSubscriberAccessorTest.php b/tests/Unit/Subscription/Subscriber/MetadataSubscriberAccessorTest.php index 2f95de93c..d2516c9af 100644 --- a/tests/Unit/Subscription/Subscriber/MetadataSubscriberAccessorTest.php +++ b/tests/Unit/Subscription/Subscriber/MetadataSubscriberAccessorTest.php @@ -20,7 +20,7 @@ final class MetadataSubscriberAccessorTest extends TestCase { public function testId(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { }; @@ -34,7 +34,7 @@ class { public function testGroup(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { }; @@ -48,7 +48,7 @@ class { public function testRunMode(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { }; @@ -62,7 +62,7 @@ class { public function testSubscribeMethod(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { #[Subscribe(ProfileCreated::class)] public function onProfileCreated(Message $message): void @@ -84,7 +84,7 @@ public function onProfileCreated(Message $message): void public function testMultipleSubscribeMethod(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { #[Subscribe(ProfileCreated::class)] public function onProfileCreated(Message $message): void @@ -112,7 +112,7 @@ public function onFoo(Message $message): void public function testSubscribeAllMethod(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { #[Subscribe('*')] public function onProfileCreated(Message $message): void @@ -134,7 +134,7 @@ public function onProfileCreated(Message $message): void public function testSetupMethod(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { #[Setup] public function method(): void @@ -154,7 +154,7 @@ public function method(): void public function testNotSetupMethod(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { }; @@ -170,7 +170,7 @@ class { public function testTeardownMethod(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { #[Teardown] public function method(): void @@ -190,7 +190,7 @@ public function method(): void public function testNotTeardownMethod(): void { - $subscriber = new #[Subscriber('profile')] + $subscriber = new #[Subscriber('profile', RunMode::FromBeginning)] class { }; diff --git a/tests/Unit/Subscription/Subscriber/SubscriberHelperTest.php b/tests/Unit/Subscription/Subscriber/SubscriberHelperTest.php index 305da7a48..900156c7f 100644 --- a/tests/Unit/Subscription/Subscriber/SubscriberHelperTest.php +++ b/tests/Unit/Subscription/Subscriber/SubscriberHelperTest.php @@ -5,6 +5,7 @@ namespace Patchlevel\EventSourcing\Tests\Unit\Subscription\Subscriber; use Patchlevel\EventSourcing\Attribute\Subscriber; +use Patchlevel\EventSourcing\Subscription\RunMode; use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberHelper; use PHPUnit\Framework\TestCase; @@ -13,7 +14,7 @@ final class SubscriberHelperTest extends TestCase { public function testSubscriberId(): void { - $subscriber = new #[Subscriber('dummy')] + $subscriber = new #[Subscriber('dummy', RunMode::FromBeginning)] class { };