Skip to content

Commit

Permalink
dont teardown new subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Oct 16, 2024
1 parent 24213f7 commit 3dcfb69
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Subscription/Engine/DefaultSubscriptionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,19 @@ function (array $subscriptions): Result {
$errors = [];

foreach ($subscriptions as $subscription) {
if ($subscription->isNew()) {
$this->subscriptionStore->remove($subscription);

Check failure on line 579 in src/Subscription/Engine/DefaultSubscriptionEngine.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

UndefinedThisPropertyFetch

src/Subscription/Engine/DefaultSubscriptionEngine.php:579:25: UndefinedThisPropertyFetch: Instance property Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine::$subscriptionStore is not defined (see https://psalm.dev/041)

Check failure on line 579 in src/Subscription/Engine/DefaultSubscriptionEngine.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

MixedMethodCall

src/Subscription/Engine/DefaultSubscriptionEngine.php:579:51: MixedMethodCall: Cannot determine the type of $this->subscriptionStore when calling method remove (see https://psalm.dev/015)

Check failure on line 579 in src/Subscription/Engine/DefaultSubscriptionEngine.php

View workflow job for this annotation

GitHub Actions / Static Analysis by PHPStan (locked, 8.3, ubuntu-latest)

Access to an undefined property Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine::$subscriptionStore.

$this->logger?->info(
sprintf(
'Subscription Engine: Subscription "%s" removed.',
$subscription->id(),
),
);

continue;
}

$subscriber = $this->subscriber($subscription->id());

if (!$subscriber) {
Expand Down
41 changes: 41 additions & 0 deletions tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 3dcfb69

Please sign in to comment.