Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 4, 2024
1 parent fc1aa26 commit 8188b39
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 44 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 @@ -313,7 +313,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,9 +18,11 @@
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\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\GherkinTableNodeBasedContentDimensionSource;
use Neos\EventStore\EventStoreInterface;

/**
* Subject provider for behavioral tests
Expand All @@ -32,6 +34,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 @@ -126,7 +134,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 @@ -172,11 +180,10 @@ protected function setUpContentRepository(ContentRepositoryId $contentRepository
if (!in_array($contentRepository->id, self::$alreadySetUpContentRepositories)) {
$contentRepository->setUp();
self::$alreadySetUpContentRepositories[] = $contentRepository->id;
unset($this->contentRepositoryServiceFactoryDependenciesById[$contentRepositoryId->value]);
}
/** @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);
$contentRepository->resetProjectionStates();
Expand All @@ -185,4 +192,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 @@ -231,6 +231,7 @@ protected function getObject(string $className): object
}

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 @@ -59,6 +59,7 @@ public function setupCrImportExportTrait()
public function theEventsAreExportedIExpectTheFollowingJsonl()
{
$eventExporter = $this->getContentRepositoryService(
$this->currentContentRepository->id,
new class ($this->crImportExportTrait_filesystem) implements ContentRepositoryServiceFactoryInterface {
public function __construct(private readonly Filesystem $filesystem)
{
Expand Down Expand Up @@ -90,6 +91,7 @@ public function build(ContentRepositoryServiceFactoryDependencies $serviceFactor
public function iImportTheFollowingJson(?string $contentStreamId = null)
{
$eventImporter = $this->getContentRepositoryService(
$this->currentContentRepository->id,
new class ($this->crImportExportTrait_filesystem, $contentStreamId ? ContentStreamId::fromString($contentStreamId) : null) implements ContentRepositoryServiceFactoryInterface {
public function __construct(
private readonly Filesystem $filesystem,
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 @@ -133,7 +133,7 @@ public function build(ContentRepositoryServiceFactoryDependencies $serviceFactor
};
}
};
$this->getContentRepositoryService($propertyConverterAccess);
$this->getContentRepositoryService($this->currentContentRepository->id, $propertyConverterAccess);

$migration = new NodeDataToEventsProcessor(
$nodeTypeManager,
Expand Down Expand Up @@ -400,6 +400,7 @@ private function parseJsonTable(TableNode $table): array
}

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 @@ -17,9 +17,6 @@
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryDependencies;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceInterface;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\CatchUpOptions;
Expand Down Expand Up @@ -242,7 +239,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 @@ -252,37 +249,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 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()
return $this->getContentRepositoryServiceFactoryDependencies($this->currentContentRepository->id)
->projectionsAndCatchUpHooks
->contentGraphProjection
->getState();
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 @@ -93,6 +93,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 8188b39

Please sign in to comment.