Skip to content

Commit

Permalink
TASK: Test that reset also resets detached projections if they are re…
Browse files Browse the repository at this point in the history
…installed
  • Loading branch information
mhsdesign committed Dec 16, 2024
1 parent b76f80e commit 6b90c92
Showing 1 changed file with 67 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ public function projectionIsDetachedOnCatchupActive()
// commit an event
$this->commitExampleContentStreamEvent();

$mockSettings = $this->getObject(ConfigurationManager::class)->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepositoryRegistry');
unset($mockSettings['contentRepositories'][$this->contentRepository->id->value]['projections']['Vendor.Package:FakeProjection']);
$this->getObject(ContentRepositoryRegistry::class)->injectSettings($mockSettings);
$this->getObject(ContentRepositoryRegistry::class)->resetFactoryInstance($this->contentRepository->id);
$this->setupContentRepositoryDependencies($this->contentRepository->id);
$this->uninstallProjection('Vendor.Package:FakeProjection');

self::assertEquals(
DetachedSubscriptionStatus::create(
Expand Down Expand Up @@ -132,12 +128,7 @@ public function projectionIsDetachedOnSetupAndReattachedIfPossible()
$this->expectOkayStatus('Vendor.Package:FakeProjection', SubscriptionStatus::ACTIVE, SequenceNumber::fromInteger(1));

// "uninstall" the projection
$originalSettings = $this->getObject(ConfigurationManager::class)->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepositoryRegistry');
$mockSettings = $originalSettings;
unset($mockSettings['contentRepositories'][$this->contentRepository->id->value]['projections']['Vendor.Package:FakeProjection']);
$this->getObject(ContentRepositoryRegistry::class)->injectSettings($mockSettings);
$this->getObject(ContentRepositoryRegistry::class)->resetFactoryInstance($this->contentRepository->id);
$this->setupContentRepositoryDependencies($this->contentRepository->id);
$this->uninstallProjection('Vendor.Package:FakeProjection');

$this->fakeProjection->expects(self::never())->method('apply');
// setup to find detached subscribers
Expand All @@ -156,9 +147,7 @@ public function projectionIsDetachedOnSetupAndReattachedIfPossible()
);

// "reinstall" the projection
$this->getObject(ContentRepositoryRegistry::class)->injectSettings($originalSettings);
$this->getObject(ContentRepositoryRegistry::class)->resetFactoryInstance($this->contentRepository->id);
$this->setupContentRepositoryDependencies($this->contentRepository->id);
$this->reinstallProjections();

self::assertEquals(
ProjectionSubscriptionStatus::create(
Expand All @@ -177,4 +166,68 @@ public function projectionIsDetachedOnSetupAndReattachedIfPossible()

$this->expectOkayStatus('Vendor.Package:FakeProjection', SubscriptionStatus::ACTIVE, SequenceNumber::fromInteger(1));
}

/** @test */
public function projectionIsDetachedOnSetupAndReattachedViaResetIfPossible()
{
$this->fakeProjection->expects(self::once())->method('setUp');
$this->fakeProjection->expects(self::once())->method('apply');
$this->fakeProjection->expects(self::once())->method('resetState');
$this->fakeProjection->expects(self::any())->method('status')->willReturn(ProjectionStatus::ok());

$this->eventStore->setup();
$this->subscriptionEngine->setup();

$this->commitExampleContentStreamEvent();

$result = $this->subscriptionEngine->boot();
self::assertEquals(ProcessedResult::success(1), $result);

$this->expectOkayStatus('Vendor.Package:FakeProjection', SubscriptionStatus::ACTIVE, SequenceNumber::fromInteger(1));

// "uninstall" the projection
$this->uninstallProjection('Vendor.Package:FakeProjection');

$this->fakeProjection->expects(self::never())->method('apply');
// setup to find detached subscribers
$result = $this->subscriptionEngine->setup();
self::assertNull($result->errors);

$expectedDetachedState = DetachedSubscriptionStatus::create(
subscriptionId: SubscriptionId::fromString('Vendor.Package:FakeProjection'),
subscriptionStatus: SubscriptionStatus::DETACHED,
subscriptionPosition: SequenceNumber::fromInteger(1)
);

self::assertEquals(
$expectedDetachedState,
$this->subscriptionStatus('Vendor.Package:FakeProjection')
);

// "reinstall" the projection
$this->reinstallProjections();

// reset does re-attach the projection if its found again
$result = $this->subscriptionEngine->reset(SubscriptionEngineCriteria::create([SubscriptionId::fromString('Vendor.Package:FakeProjection')]));
self::assertNull($result->errors);

$this->expectOkayStatus('Vendor.Package:FakeProjection', SubscriptionStatus::BOOTING, SequenceNumber::fromInteger(0));
}

private function uninstallProjection(string $projectionName): void
{
$originalSettings = $this->getObject(ConfigurationManager::class)->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepositoryRegistry');
$mockSettings = $originalSettings;
unset($mockSettings['contentRepositories'][$this->contentRepository->id->value]['projections'][$projectionName]);
$this->getObject(ContentRepositoryRegistry::class)->injectSettings($mockSettings);
$this->getObject(ContentRepositoryRegistry::class)->resetFactoryInstance($this->contentRepository->id);
$this->setupContentRepositoryDependencies($this->contentRepository->id);
}

private function reinstallProjections(): void
{
$this->resetContentRepositoryRegistry();
$this->getObject(ContentRepositoryRegistry::class)->resetFactoryInstance($this->contentRepository->id);
$this->setupContentRepositoryDependencies($this->contentRepository->id);
}
}

0 comments on commit 6b90c92

Please sign in to comment.