Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jan 14, 2025
1 parent 07bbe1b commit 6a5fe44
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function resetContentRepositoryComponents(BeforeScenarioScope $scope): vo
}

protected function getContentRepositoryService(
ContentRepositoryId $contentRepositoryId,
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface {
return $this->contentRepositoryRegistry->buildService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ private function transformPayloadTableToDataset(TableNode $payloadTable): array
*/
public function iRunIntegrityViolationDetection(): void
{
$projectionIntegrityViolationDetectionRunner = $this->getContentRepositoryService(new DoctrineDbalProjectionIntegrityViolationDetectionRunnerFactory($this->dbal));
$projectionIntegrityViolationDetectionRunner = $this->getContentRepositoryService(
$this->currentContentRepository->id,
new DoctrineDbalProjectionIntegrityViolationDetectionRunnerFactory($this->dbal)
);
$this->lastIntegrityViolationDetectionResult = $projectionIntegrityViolationDetectionRunner->run();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
use Behat\Gherkin\Node\TableNode;
use Doctrine\DBAL\Connection;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryDependencies;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceInterface;
use Neos\ContentRepository\Core\Service\ContentRepositoryMaintainerFactory;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\Subscription\Engine\SubscriptionEngine;
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\GherkinTableNodeBasedContentDimensionSource;
use Neos\ContentRepository\TestSuite\Fakes\FakeContentDimensionSourceFactory;
use Neos\ContentRepository\TestSuite\Fakes\FakeNodeTypeManagerFactory;
use Neos\EventStore\EventStoreInterface;
use PHPUnit\Framework\Assert;
use Symfony\Component\Yaml\Yaml;

Expand All @@ -38,6 +40,12 @@ trait CRBehavioralTestsSubjectProvider
*/
protected array $contentRepositories = [];

/**
* @internal {@see getContentRepositoryServiceFactoryDependencies}
* @var array<string,ContentRepositoryServiceFactoryDependencies>
*/
protected array $contentRepositoryServiceFactoryDependenciesById = [];

/**
* A runtime cache of all content repositories already set up, represented by their ID
* @var array<ContentRepositoryId>
Expand Down Expand Up @@ -138,7 +146,7 @@ public function iChangeTheNodeTypesInContentRepositoryTo(
}
}

protected function setUpContentRepository(ContentRepositoryId $contentRepositoryId): ContentRepository
final protected function setUpContentRepository(ContentRepositoryId $contentRepositoryId): ContentRepository
{
/**
* Reset events and projections
Expand Down Expand Up @@ -186,12 +194,10 @@ protected function setUpContentRepository(ContentRepositoryId $contentRepository
$result = $contentRepositoryMaintainer->setUp();
Assert::assertNull($result);
self::$alreadySetUpContentRepositories[] = $contentRepository->id;
unset($this->contentRepositoryServiceFactoryDependenciesById[$contentRepositoryId->value]);
}
// todo we TRUNCATE here and do not want to use $contentRepositoryMaintainer->prune(); here as it would not reset the autoincrement sequence number making some assertions impossible
/** @var EventStoreInterface $eventStore */
$eventStore = (new \ReflectionClass($contentRepository))->getProperty('eventStore')->getValue($contentRepository);
/** @var Connection $databaseConnection */
$databaseConnection = (new \ReflectionClass($eventStore))->getProperty('connection')->getValue($eventStore);
$databaseConnection = $this->getObject(Connection::class);
$eventTableName = sprintf('cr_%s_events', $contentRepositoryId->value);
$databaseConnection->executeStatement('TRUNCATE ' . $eventTableName);

Expand All @@ -206,4 +212,26 @@ protected function setUpContentRepository(ContentRepositoryId $contentRepository
}

abstract protected function createContentRepository(ContentRepositoryId $contentRepositoryId): ContentRepository;

/**
* Access content repository services.
*
* @template T of ContentRepositoryServiceInterface
* @param ContentRepositoryServiceFactoryInterface<T> $contentRepositoryServiceFactory
* @return T
*/
abstract protected function getContentRepositoryService(
ContentRepositoryId $contentRepositoryId,
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface;

final protected function getContentRepositoryServiceFactoryDependencies(ContentRepositoryId $contentRepositoryId): ContentRepositoryServiceFactoryDependencies
{
if (!isset($this->contentRepositoryServiceFactoryDependenciesById[$contentRepositoryId->value])) {
$accessor = new ContentRepositoryInternalsAccessor();
$this->getContentRepositoryService($contentRepositoryId, $accessor);
$this->contentRepositoryServiceFactoryDependenciesById[$contentRepositoryId->value] = $accessor->spiedInternals;
}
return $this->contentRepositoryServiceFactoryDependenciesById[$contentRepositoryId->value];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Neos\ContentRepository\BehavioralTests\TestSuite\Behavior;

use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryDependencies;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceInterface;

class ContentRepositoryInternalsAccessor implements ContentRepositoryServiceFactoryInterface
{
public ContentRepositoryServiceFactoryDependencies $spiedInternals;
public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface
{
$this->spiedInternals = $serviceFactoryDependencies;
return new class implements ContentRepositoryServiceInterface
{
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function resetContentRepositoryComponents(BeforeScenarioScope $scope): vo
}

protected function getContentRepositoryService(
ContentRepositoryId $contentRepositoryId,
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface {
return $this->contentRepositoryRegistry->buildService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private function runCrImportExportProcessors(ProcessorInterface ...$processors):
*/
public function theEventsAreExported(): void
{
$eventExporter = $this->getContentRepositoryService(new EventExportProcessorFactory($this->currentContentRepository->findWorkspaceByName(WorkspaceName::forLive())->currentContentStreamId));
$eventExporter = $this->getContentRepositoryService($this->currentContentRepository->id,
new EventExportProcessorFactory($this->currentContentRepository->findWorkspaceByName(WorkspaceName::forLive())->currentContentStreamId));
assert($eventExporter instanceof EventExportProcessor);
$this->runCrImportExportProcessors($eventExporter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function resetContentRepositoryComponents(BeforeScenarioScope $scope): vo
}

protected function getContentRepositoryService(
ContentRepositoryId $contentRepositoryId,
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface {
return $this->contentRepositoryRegistry->buildService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function build(ContentRepositoryServiceFactoryDependencies $serviceFactor
};
}
};
$this->getContentRepositoryService($crInternalsAccess);
$this->getContentRepositoryService($this->currentContentRepository->id, $crInternalsAccess);

$eventExportProcessor = new EventExportProcessor(
$nodeTypeManager,
Expand Down Expand Up @@ -255,6 +255,7 @@ public function iRunTheSiteMigration(): void
/** ---------------------------------- */

protected function getContentRepositoryService(
ContentRepositoryId $contentRepositoryId,
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface {
return $this->contentRepositoryRegistry->buildService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected function getRootNodeAggregateId(): ?NodeAggregateId
*/
public function iPruneRemovedContentStreamsFromTheEventStream(): void
{
$this->getContentRepositoryService(new ContentStreamPrunerFactory())->pruneRemovedFromEventStream(fn () => null);
$this->getContentRepositoryService($this->currentContentRepository->id, new ContentStreamPrunerFactory())->pruneRemovedFromEventStream(fn () => null);
}

/**
Expand All @@ -227,20 +227,15 @@ public function iExpectTheContentStreamStatus(PyStringNode $pyStringNode): void
{
// todo a little dirty to compare the cli output here :D
$lines = [];
$this->getContentRepositoryService(new ContentStreamPrunerFactory())->outputStatus(function ($line = '') use (&$lines) {
$this->getContentRepositoryService($this->currentContentRepository->id, new ContentStreamPrunerFactory())->outputStatus(function ($line = '') use (&$lines) {
$lines[] = $line;
});
Assert::assertSame($pyStringNode->getRaw(), join("\n", $lines));
}


abstract protected function getContentRepositoryService(
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface;

final protected function getContentGraphReadModel(): ContentGraphReadModelInterface
{
return $this->getContentRepositoryService(new class implements ContentRepositoryServiceFactoryInterface {
return $this->getContentRepositoryService($this->currentContentRepository->id, new class implements ContentRepositoryServiceFactoryInterface {
public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface
{
$contentGraphReadModel = $serviceFactoryDependencies->contentGraphReadModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function iRunTheFollowingNodeMigrationWithTargetWorkspace(string $sourceW
ContentStreamId::fromString($contentStreamId)
);

/** @var NodeMigrationService $nodeMigrationService */
$nodeMigrationService = $this->getContentRepositoryService(new NodeMigrationServiceFactory());
$nodeMigrationService = $this->getContentRepositoryService($this->currentContentRepository->id, new NodeMigrationServiceFactory());
$nodeMigrationService->executeMigration($command);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ trait StructureAdjustmentsTrait
*/
public function iAdjustTheNodeStructureForNodeType(string $nodeTypeName): void
{
/** @var StructureAdjustmentService $structureAdjustmentService */
$structureAdjustmentService = $this->getContentRepositoryService(new StructureAdjustmentServiceFactory());
$structureAdjustmentService = $this->getContentRepositoryService($this->currentContentRepository->id, new StructureAdjustmentServiceFactory());
$errors = $structureAdjustmentService->findAdjustmentsForNodeType(NodeTypeName::fromString($nodeTypeName));
foreach ($errors as $error) {
$structureAdjustmentService->fixError($error);
Expand All @@ -49,8 +48,7 @@ public function iAdjustTheNodeStructureForNodeType(string $nodeTypeName): void
*/
public function iExpectNoStructureAdjustmentsForType(string $nodeTypeName): void
{
/** @var StructureAdjustmentService $structureAdjustmentService */
$structureAdjustmentService = $this->getContentRepositoryService(new StructureAdjustmentServiceFactory());
$structureAdjustmentService = $this->getContentRepositoryService($this->currentContentRepository->id, new StructureAdjustmentServiceFactory());
$errors = $structureAdjustmentService->findAdjustmentsForNodeType(NodeTypeName::fromString($nodeTypeName));
$errors = iterator_to_array($errors);
Assert::assertEmpty($errors, implode(', ', array_map(fn (StructureAdjustment $adjustment) => $adjustment->render(), $errors)));
Expand All @@ -62,8 +60,7 @@ public function iExpectNoStructureAdjustmentsForType(string $nodeTypeName): void
*/
public function iExpectTheFollowingStructureAdjustmentsForType(string $nodeTypeName, TableNode $expectedAdjustments): void
{
/** @var StructureAdjustmentService $structureAdjustmentService */
$structureAdjustmentService = $this->getContentRepositoryService(new StructureAdjustmentServiceFactory());
$structureAdjustmentService = $this->getContentRepositoryService($this->currentContentRepository->id, new StructureAdjustmentServiceFactory());
$actualAdjustments = $structureAdjustmentService->findAdjustmentsForNodeType(NodeTypeName::fromString($nodeTypeName));
$actualAdjustments = iterator_to_array($actualAdjustments);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function resetPersistenceManagerAndFeedbackCollection()
}

protected function getContentRepositoryService(
ContentRepositoryId $contentRepositoryId,
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface {
return $this->contentRepositoryRegistry->buildService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function iExpectThisNodeToBeDisabled(): void
}

protected function getContentRepositoryService(
ContentRepositoryId $contentRepositoryId,
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface {
return $this->contentRepositoryRegistry->buildService(
Expand Down

0 comments on commit 6a5fe44

Please sign in to comment.