From 9375fd92cead9601e868b31de8254ba6ee98713a Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:01:57 +0100 Subject: [PATCH] TASK: Make `findContentStreamById` fully internal (like `countNodes`) --- .../Classes/ContentRepository.php | 7 --- .../ContentGraphReadModelInterface.php | 3 ++ .../Features/Bootstrap/CRTestSuiteTrait.php | 44 ++++++++++++------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/ContentRepository.php b/Neos.ContentRepository.Core/Classes/ContentRepository.php index 7f12b3c8be1..b6e0708ed01 100644 --- a/Neos.ContentRepository.Core/Classes/ContentRepository.php +++ b/Neos.ContentRepository.Core/Classes/ContentRepository.php @@ -38,8 +38,6 @@ use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryStatus; use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; use Neos\ContentRepository\Core\SharedModel\User\UserIdProviderInterface; -use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStream; -use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces; @@ -250,11 +248,6 @@ public function findWorkspaces(): Workspaces return $this->contentGraphReadModel->findWorkspaces(); } - public function findContentStreamById(ContentStreamId $contentStreamId): ?ContentStream - { - return $this->contentGraphReadModel->findContentStreamById($contentStreamId); - } - public function getNodeTypeManager(): NodeTypeManager { return $this->nodeTypeManager; diff --git a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php index c44dc7379aa..58232977141 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php +++ b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php @@ -37,6 +37,9 @@ public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace; public function findWorkspaces(): Workspaces; + /** + * @internal only used for constraint checks and in testcases + */ public function findContentStreamById(ContentStreamId $contentStreamId): ?ContentStream; /** diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php index 18fddc56f68..f0e71b8027e 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php @@ -132,7 +132,7 @@ protected function readPayloadTable(TableNode $payloadTable): array */ public function iExpectTheContentStreamToExist(string $rawContentStreamId): void { - $contentStream = $this->currentContentRepository->findContentStreamById(ContentStreamId::fromString($rawContentStreamId)); + $contentStream = $this->getContentGraphReadModel()->findContentStreamById(ContentStreamId::fromString($rawContentStreamId)); Assert::assertNotNull($contentStream, sprintf('Content stream "%s" was expected to exist, but it does not', $rawContentStreamId)); } @@ -141,7 +141,7 @@ public function iExpectTheContentStreamToExist(string $rawContentStreamId): void */ public function iExpectTheContentStreamToNotExist(string $rawContentStreamId, string $not = ''): void { - $contentStream = $this->currentContentRepository->findContentStreamById(ContentStreamId::fromString($rawContentStreamId)); + $contentStream = $this->getContentGraphReadModel()->findContentStreamById(ContentStreamId::fromString($rawContentStreamId)); Assert::assertNull($contentStream, sprintf('Content stream "%s" was not expected to exist, but it does', $rawContentStreamId)); } @@ -166,20 +166,7 @@ public function workspaceStatusMatchesExpected(string $rawWorkspaceNames, string */ public function iExpectTheGraphProjectionToConsistOfExactlyNodes(int $expectedNumberOfNodes): void { - // HACK to access - $contentGraphReadModelAccess = new class implements ContentRepositoryServiceFactoryInterface { - public ContentGraphReadModelInterface|null $instance; - public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface - { - $this->instance = $serviceFactoryDependencies->projectionsAndCatchUpHooks->contentGraphProjection->getState(); - return new class implements ContentRepositoryServiceInterface - { - }; - } - }; - $this->getContentRepositoryService($contentGraphReadModelAccess); - - $actualNumberOfNodes = $contentGraphReadModelAccess->instance->countNodes(); + $actualNumberOfNodes = $this->getContentGraphReadModel()->countNodes(); Assert::assertSame($expectedNumberOfNodes, $actualNumberOfNodes, 'Content graph consists of ' . $actualNumberOfNodes . ' nodes, expected were ' . $expectedNumberOfNodes . '.'); } @@ -276,6 +263,31 @@ abstract protected function getContentRepositoryService( ContentRepositoryServiceFactoryInterface $factory ): ContentRepositoryServiceInterface; + final protected function getContentRepositoryServiceFactoryDependencies(): ContentRepositoryServiceFactoryDependencies + { + $accessorFactory = new class implements ContentRepositoryServiceFactoryInterface { + public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface + { + return new class ($serviceFactoryDependencies) implements ContentRepositoryServiceInterface + { + public function __construct( + public readonly ContentRepositoryServiceFactoryDependencies $dependencies + ) { + } + }; + } + }; + return $this->getContentRepositoryService($accessorFactory)->dependencies; + } + + final protected function getContentGraphReadModel(): ContentGraphReadModelInterface + { + return $this->getContentRepositoryServiceFactoryDependencies() + ->projectionsAndCatchUpHooks + ->contentGraphProjection + ->getState(); + } + /** * @When I replay the :projectionName projection */