diff --git a/src/Subscription/Engine/DefaultSubscriptionEngine.php b/src/Subscription/Engine/DefaultSubscriptionEngine.php index e4ffbd339..8e352dee3 100644 --- a/src/Subscription/Engine/DefaultSubscriptionEngine.php +++ b/src/Subscription/Engine/DefaultSubscriptionEngine.php @@ -575,6 +575,19 @@ function (array $subscriptions): Result { $errors = []; foreach ($subscriptions as $subscription) { + if ($subscription->isNew()) { + $this->subscriptionManager->remove($subscription); + + $this->logger?->info( + sprintf( + 'Subscription Engine: Subscription "%s" removed.', + $subscription->id(), + ), + ); + + continue; + } + $subscriber = $this->subscriber($subscription->id()); if (!$subscriber) { diff --git a/tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php b/tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php index 0a9b92538..bef49ed46 100644 --- a/tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php +++ b/tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php @@ -2530,6 +2530,47 @@ public function drop(): void self::assertEquals([$subscription], $subscriptionStore->removedSubscriptions); } + public function testRemoveNewSubscriber(): void + { + $subscriptionId = 'test'; + $subscriber = new #[Subscriber('test', RunMode::FromBeginning)] + class { + public bool $dropped = false; + + #[Teardown] + public function drop(): void + { + $this->dropped = true; + } + }; + + $subscription = new Subscription( + $subscriptionId, + Subscription::DEFAULT_GROUP, + RunMode::FromBeginning, + Status::New, + ); + + $subscriptionStore = new DummySubscriptionStore([$subscription]); + + $streamableStore = $this->prophesize(Store::class); + + $engine = new DefaultSubscriptionEngine( + $streamableStore->reveal(), + $subscriptionStore, + new MetadataSubscriberAccessorRepository([$subscriber]), + logger: new NullLogger(), + ); + + $result = $engine->remove(); + + self::assertEquals([], $result->errors); + + self::assertEquals([], $subscriptionStore->updatedSubscriptions); + self::assertEquals([$subscription], $subscriptionStore->removedSubscriptions); + self::assertFalse($subscriber->dropped); + } + public function testRemoveWithoutSubscriber(): void { $subscriberId = 'test';