Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content Repository Test Suite #4455

Merged
merged 39 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0454bf0
Introduce test support suite package
Jul 13, 2023
93da115
Declare test suite package in distribution
Jul 13, 2023
ace0152
Rename test suite package
Jul 13, 2023
9d747cf
Fix namespace
Jul 13, 2023
6658ba4
Add autoloading to test suite
Jul 13, 2023
7bdd4e8
Merge branch '9.0' into testSuite
Jul 31, 2023
3ea1df2
Merge branch '9.0' into testSuite
Aug 1, 2023
bf16879
Extract feature traits to TestSuite package
Aug 1, 2023
6e86c07
Introduce the test suite to linting
Aug 1, 2023
9f0cbe2
WIP: Adjust test suite
Aug 17, 2023
7176e5a
Adjust NodeTraversal tests
Aug 17, 2023
80653e5
Adjust NodeTypeChange tests
Aug 17, 2023
f6be389
Adjust final test cases
Aug 17, 2023
86071fd
Clean up stuff
Aug 17, 2023
b79dcb4
Merge branch '9.0' into testSuite
Aug 17, 2023
b16bde1
Pacify linter
Aug 17, 2023
d614486
(hopefully) Increase readability of tests
Aug 18, 2023
ce3589d
Further separate tests from CR registry
Aug 18, 2023
9934739
Run tests only on one graph adapter
Aug 18, 2023
4e87058
Extract CurrentSubgraphTrait
Aug 18, 2023
673a6e3
Move test helpers / bootstrap traits to respective packages
Aug 18, 2023
087a0a6
Adjust behavioral tests to registry architecture
Aug 19, 2023
c52215f
Make CRRegistrySubjectProvider work for 3rd party applications
Aug 19, 2023
86e020a
Pacify linter
Aug 19, 2023
cec6451
Require behat and phpunit
Aug 20, 2023
d2f90b8
Adjust DBAL adapter tests
Aug 20, 2023
8bdd842
Revert obsolete changes on ContentRepositoryRegistry::buildFactory
Aug 20, 2023
8e63465
Clean up higher level feature contexts
Aug 20, 2023
f0720dd
run CR setup before cleanup
Aug 25, 2023
c51663d
Remove implicit dependency from TestSuite to BehavioralTests
Aug 25, 2023
3d0a7eb
properly name reset method and correct nodeTypeManager::getNodeTypes …
Aug 25, 2023
a182756
Adjust DoctrineDBAL adapter and Neos test suites
Aug 25, 2023
fb4714a
Adjust Neos.Neos behavioral tests
Aug 25, 2023
d7fea93
Fix typo
Aug 26, 2023
373d253
Merge branch '9.0' into testSuite
Aug 26, 2023
b3e6431
Move test suite helpers to test folders to avoid autoloading in non-t…
Aug 29, 2023
e12ebe4
Move BT helpers
Aug 29, 2023
d994260
Revert "Move BT helpers"
Aug 29, 2023
b11cbe4
Revert "Move test suite helpers to test folders to avoid autoloading …
Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentGraph;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ProjectionContentGraph;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\EventStore\EventNormalizer;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\ContentStreamForking\Event\ContentStreamWasForked;
use Neos\ContentRepository\Core\Feature\ContentStreamRemoval\Event\ContentStreamWasRemoved;
use Neos\ContentRepository\Core\Feature\DimensionSpaceAdjustment\Event\DimensionShineThroughWasAdded;
use Neos\ContentRepository\Core\Feature\DimensionSpaceAdjustment\Event\DimensionSpacePointWasMoved;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\NodeDisabling\Event\NodeAggregateWasDisabled;
use Neos\ContentRepository\Core\Feature\NodeDisabling\Event\NodeAggregateWasEnabled;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\Feature\NodeModification\Event\NodePropertiesWereSet;
use Neos\ContentRepository\Core\Feature\NodeMove\Event\NodeAggregateWasMoved;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\SerializedNodeReference;
Expand All @@ -44,25 +44,21 @@
use Neos\ContentRepository\Core\Feature\RootNodeCreation\Event\RootNodeAggregateDimensionsWereUpdated;
use Neos\ContentRepository\Core\Feature\RootNodeCreation\Event\RootNodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Infrastructure\DbalClientInterface;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface;
use Neos\ContentRepository\Core\Projection\CatchUpHookInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Timestamps;
use Neos\ContentRepository\Core\Projection\ProjectionInterface;
use Neos\ContentRepository\Core\Projection\WithMarkStaleInterface;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\EventStore\CatchUp\CatchUp;
use Neos\EventStore\CatchUp\CheckpointStorageInterface;
use Neos\EventStore\DoctrineAdapter\DoctrineCheckpointStorage;
use Neos\EventStore\Model\Event;
use Neos\EventStore\Model\Event\SequenceNumber;
use Neos\EventStore\Model\EventEnvelope;
use Neos\EventStore\Model\EventStore\SetupResult;
use Neos\EventStore\Model\EventStream\EventStreamInterface;
use Neos\EventStore\Model\Event\SequenceNumber;

/**
* @implements ProjectionInterface<ContentGraph>
Expand All @@ -88,12 +84,10 @@ final class DoctrineDbalContentGraphProjection implements ProjectionInterface, W
private DoctrineCheckpointStorage $checkpointStorage;

public function __construct(
private readonly EventNormalizer $eventNormalizer,
private readonly DbalClientInterface $dbalClient,
private readonly NodeFactory $nodeFactory,
private readonly NodeTypeManager $nodeTypeManager,
private readonly ProjectionContentGraph $projectionContentGraph,
private readonly CatchUpHookFactoryInterface $catchUpHookFactory,
private readonly string $tableNamePrefix,
) {
$this->checkpointStorage = new DoctrineCheckpointStorage(
Expand Down Expand Up @@ -158,10 +152,9 @@ private function truncateDatabaseTables(): void
$connection->executeQuery('TRUNCATE table ' . $this->tableNamePrefix . '_restrictionrelation');
}

public function canHandle(Event $event): bool
public function canHandle(EventInterface $event): bool
{
$eventClassName = $this->eventNormalizer->getEventClassName($event);
return in_array($eventClassName, [
return in_array($event::class, [
RootNodeAggregateWithNodeWasCreated::class,
RootNodeAggregateDimensionsWereUpdated::class,
NodeAggregateWithNodeWasCreated::class,
Expand All @@ -183,75 +176,34 @@ public function canHandle(Event $event): bool
]);
}

public function catchUp(EventStreamInterface $eventStream, ContentRepository $contentRepository): void
public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
{
$catchUpHook = $this->catchUpHookFactory->build($contentRepository);
$catchUpHook->onBeforeCatchUp();
$catchUp = CatchUp::create(
fn(EventEnvelope $eventEnvelope) => $this->apply($eventEnvelope, $catchUpHook),
$this->checkpointStorage
);
$catchUp = $catchUp->withOnBeforeBatchCompleted(fn() => $catchUpHook->onBeforeBatchCompleted());
$catchUp->run($eventStream);
$catchUpHook->onAfterCatchUp();
}

private function apply(EventEnvelope $eventEnvelope, CatchUpHookInterface $catchUpHook): void
{
if (!$this->canHandle($eventEnvelope->event)) {
return;
}

$eventInstance = $this->eventNormalizer->denormalize($eventEnvelope->event);

$catchUpHook->onBeforeEvent($eventInstance, $eventEnvelope);

if ($eventInstance instanceof RootNodeAggregateWithNodeWasCreated) {
$this->whenRootNodeAggregateWithNodeWasCreated($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof RootNodeAggregateDimensionsWereUpdated) {
$this->whenRootNodeAggregateDimensionsWereUpdated($eventInstance);
} elseif ($eventInstance instanceof NodeAggregateWithNodeWasCreated) {
$this->whenNodeAggregateWithNodeWasCreated($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof NodeAggregateNameWasChanged) {
$this->whenNodeAggregateNameWasChanged($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof ContentStreamWasForked) {
$this->whenContentStreamWasForked($eventInstance);
} elseif ($eventInstance instanceof ContentStreamWasRemoved) {
$this->whenContentStreamWasRemoved($eventInstance);
} elseif ($eventInstance instanceof NodePropertiesWereSet) {
$this->whenNodePropertiesWereSet($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof NodeReferencesWereSet) {
$this->whenNodeReferencesWereSet($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof NodeAggregateWasEnabled) {
$this->whenNodeAggregateWasEnabled($eventInstance);
} elseif ($eventInstance instanceof NodeAggregateTypeWasChanged) {
$this->whenNodeAggregateTypeWasChanged($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof DimensionSpacePointWasMoved) {
$this->whenDimensionSpacePointWasMoved($eventInstance);
} elseif ($eventInstance instanceof DimensionShineThroughWasAdded) {
$this->whenDimensionShineThroughWasAdded($eventInstance);
} elseif ($eventInstance instanceof NodeAggregateWasRemoved) {
$this->whenNodeAggregateWasRemoved($eventInstance);
} elseif ($eventInstance instanceof NodeAggregateWasMoved) {
$this->whenNodeAggregateWasMoved($eventInstance);
} elseif ($eventInstance instanceof NodeSpecializationVariantWasCreated) {
$this->whenNodeSpecializationVariantWasCreated($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof NodeGeneralizationVariantWasCreated) {
$this->whenNodeGeneralizationVariantWasCreated($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof NodePeerVariantWasCreated) {
$this->whenNodePeerVariantWasCreated($eventInstance, $eventEnvelope);
} elseif ($eventInstance instanceof NodeAggregateWasDisabled) {
$this->whenNodeAggregateWasDisabled($eventInstance);
} else {
throw new \RuntimeException('Not supported: ' . get_class($eventInstance));
}

$catchUpHook->onAfterEvent($eventInstance, $eventEnvelope);
match ($event::class) {
RootNodeAggregateWithNodeWasCreated::class => $this->whenRootNodeAggregateWithNodeWasCreated($event, $eventEnvelope),
RootNodeAggregateDimensionsWereUpdated::class => $this->whenRootNodeAggregateDimensionsWereUpdated($event),
NodeAggregateWithNodeWasCreated::class => $this->whenNodeAggregateWithNodeWasCreated($event, $eventEnvelope),
NodeAggregateNameWasChanged::class => $this->whenNodeAggregateNameWasChanged($event, $eventEnvelope),
ContentStreamWasForked::class => $this->whenContentStreamWasForked($event),
ContentStreamWasRemoved::class => $this->whenContentStreamWasRemoved($event),
NodePropertiesWereSet::class => $this->whenNodePropertiesWereSet($event, $eventEnvelope),
NodeReferencesWereSet::class => $this->whenNodeReferencesWereSet($event, $eventEnvelope),
NodeAggregateWasEnabled::class => $this->whenNodeAggregateWasEnabled($event),
NodeAggregateTypeWasChanged::class => $this->whenNodeAggregateTypeWasChanged($event, $eventEnvelope),
DimensionSpacePointWasMoved::class => $this->whenDimensionSpacePointWasMoved($event),
DimensionShineThroughWasAdded::class => $this->whenDimensionShineThroughWasAdded($event),
NodeAggregateWasRemoved::class => $this->whenNodeAggregateWasRemoved($event),
NodeAggregateWasMoved::class => $this->whenNodeAggregateWasMoved($event),
NodeSpecializationVariantWasCreated::class => $this->whenNodeSpecializationVariantWasCreated($event, $eventEnvelope),
NodeGeneralizationVariantWasCreated::class => $this->whenNodeGeneralizationVariantWasCreated($event, $eventEnvelope),
NodePeerVariantWasCreated::class => $this->whenNodePeerVariantWasCreated($event, $eventEnvelope),
NodeAggregateWasDisabled::class => $this->whenNodeAggregateWasDisabled($event),
default => throw new \InvalidArgumentException(sprintf('Unsupported event %s', get_debug_type($event))),
};
}

public function getSequenceNumber(): SequenceNumber
public function getCheckpointStorage(): CheckpointStorageInterface
{
return $this->checkpointStorage->getHighestAppliedSequenceNumber();
return $this->checkpointStorage;
}

public function getState(): ContentGraph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepository\Core\Factory\ProjectionFactoryDependencies;
use Neos\ContentRepository\Core\Infrastructure\DbalClientInterface;
use Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphProjection;
use Neos\ContentRepository\Core\Projection\ProjectionFactoryInterface;
use Neos\ContentRepository\Core\Projection\ProjectionInterface;
use Neos\ContentRepository\Core\Projection\Projections;

/**
* Use this class as ProjectionFactory in your configuration to construct a content graph
Expand All @@ -38,8 +35,6 @@ public static function graphProjectionTableNamePrefix(
public function build(
ProjectionFactoryDependencies $projectionFactoryDependencies,
array $options,
CatchUpHookFactoryInterface $catchUpHookFactory,
Projections $projectionsSoFar
): ContentGraphProjection {
$tableNamePrefix = self::graphProjectionTableNamePrefix(
$projectionFactoryDependencies->contentRepositoryId
Expand All @@ -48,7 +43,6 @@ public function build(
return new ContentGraphProjection(
// @phpstan-ignore-next-line
new DoctrineDbalContentGraphProjection(
$projectionFactoryDependencies->eventNormalizer,
$this->dbalClient,
new NodeFactory(
$projectionFactoryDependencies->contentRepositoryId,
Expand All @@ -60,7 +54,6 @@ public function build(
$this->dbalClient,
$tableNamePrefix
),
$catchUpHookFactory,
$tableNamePrefix
)
);
Expand Down
Loading
Loading