Skip to content

Commit

Permalink
TASK: Make findContentStreamById fully internal (like countNodes)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 2, 2024
1 parent 6249a98 commit d0420bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
7 changes: 0 additions & 7 deletions Neos.ContentRepository.Core/Classes/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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->getContentGraphReadModelInterface()->findContentStreamById(ContentStreamId::fromString($rawContentStreamId));
Assert::assertNotNull($contentStream, sprintf('Content stream "%s" was expected to exist, but it does not', $rawContentStreamId));
}

Expand All @@ -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->getContentGraphReadModelInterface()->findContentStreamById(ContentStreamId::fromString($rawContentStreamId));
Assert::assertNull($contentStream, sprintf('Content stream "%s" was not expected to exist, but it does', $rawContentStreamId));
}

Expand All @@ -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->getContentGraphReadModelInterface()->countNodes();
Assert::assertSame($expectedNumberOfNodes, $actualNumberOfNodes, 'Content graph consists of ' . $actualNumberOfNodes . ' nodes, expected were ' . $expectedNumberOfNodes . '.');
}

Expand Down Expand Up @@ -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 getContentGraphReadModelInterface(): ContentGraphReadModelInterface
{
return $this->getContentRepositoryServiceFactoryDependencies()
->projectionsAndCatchUpHooks
->contentGraphProjection
->getState();
}

/**
* @When I replay the :projectionName projection
*/
Expand Down

0 comments on commit d0420bc

Please sign in to comment.