From 6e29ec58952e774d63611150086983a720afae6d Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 16 Jun 2024 18:53:08 +0200 Subject: [PATCH 1/3] TASK: Provide alternative for `NodeDiscriminator::fromNode` that doesnt use Nodes content stream Related #5034 and #5043 --- .../Bootstrap/CRTestSuiteRuntimeVariables.php | 15 +++++++++++---- .../Bootstrap/Helpers/NodeDiscriminator.php | 15 +++++++++++++++ .../Bootstrap/Helpers/NodeDiscriminators.php | 8 -------- .../Features/Bootstrap/ProjectedNodeTrait.php | 11 ++++++----- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php index 656e45666cc..6642d015bf7 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php @@ -17,6 +17,7 @@ use Neos\ContentRepository\Core\ContentGraphFinder; use Neos\ContentRepository\Core\ContentRepository; use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate; @@ -147,16 +148,22 @@ public function visibilityConstraintsAreSetTo(string $restrictionType): void }; } - public function getCurrentSubgraph(): ContentSubgraphInterface + public function getCurrentContentGraph(): ContentGraphInterface { + // todo cache content graph per test run??? Otherwise it will be flushed too often? $contentGraphFinder = $this->currentContentRepository->projectionState(ContentGraphFinder::class); $contentGraphFinder->forgetInstances(); - if (isset($this->currentContentStreamId)) { + if ($this->currentContentStreamId !== null) { // This must still be supported for low level tests, e.g. for content stream forking - return $contentGraphFinder->getByWorkspaceNameAndContentStreamId($this->currentWorkspaceName, $this->currentContentStreamId)->getSubgraph($this->currentDimensionSpacePoint, $this->currentVisibilityConstraints); + return $contentGraphFinder->getByWorkspaceNameAndContentStreamId($this->currentWorkspaceName, $this->currentContentStreamId); } - return $contentGraphFinder->getByWorkspaceName($this->currentWorkspaceName)->getSubgraph( + return $contentGraphFinder->getByWorkspaceName($this->currentWorkspaceName); + } + + public function getCurrentSubgraph(?ContentGraphInterface $contentGraphToUse = null): ContentSubgraphInterface + { + return ($contentGraphToUse ?? $this->getCurrentContentGraph())->getSubgraph( $this->currentDimensionSpacePoint, $this->currentVisibilityConstraints ); diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php index 005e5464e4d..8539c8c4cf5 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php @@ -15,6 +15,7 @@ namespace Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers; use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; @@ -47,6 +48,7 @@ public static function fromShorthand(string $shorthand): self ); } + /** @deprecated will be removed */ public static function fromNode(Node $node): self { return new self( @@ -56,6 +58,19 @@ public static function fromNode(Node $node): self ); } + public static function fromNodeAndContentGraph(Node $node, ContentGraphInterface $contentGraph): self + { + if (!$node->workspaceName->equals($contentGraph->getWorkspaceName())) { + throw new \InvalidArgumentException(sprintf('Expected nodes workspace %s to match given subgraph workspace %s.', $node->workspaceName->value, $contentGraph->getWorkspaceName()->value), 1718554466); + } + + return new self( + $contentGraph->getContentStreamId(), + $node->aggregateId, + $node->originDimensionSpacePoint + ); + } + public function equals(self $other): bool { return $this->contentStreamId->equals($other->contentStreamId) diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminators.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminators.php index 2bedcbce70e..07924d1de4a 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminators.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminators.php @@ -53,14 +53,6 @@ public static function fromArray(array $array): self )); } - public static function fromNodes(Nodes $nodes): self - { - return new self(...array_map( - fn (Node $node): NodeDiscriminator => NodeDiscriminator::fromNode($node), - iterator_to_array($nodes) - )); - } - public function equal(self $other): bool { return $this->discriminators == $other->discriminators; diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php index ad96bdacce4..3eeb6cbc538 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php @@ -456,15 +456,16 @@ public function iExpectThisNodeToHaveNoReferences(): void */ public function iExpectThisNodeToBeReferencedBy(TableNode $expectedReferences): void { - $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedReferences) { - $actualReferences = $this->getCurrentSubgraph() + $contentGraph = $this->getCurrentContentGraph(); + $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedReferences, $contentGraph) { + $actualReferences = $this->getCurrentSubgraph($contentGraph) ->findBackReferences($currentNode->aggregateId, FindBackReferencesFilter::create()); - $this->assertReferencesMatch($expectedReferences, $actualReferences); + $this->assertReferencesMatch($expectedReferences, $actualReferences, $contentGraph); }); } - private function assertReferencesMatch(TableNode $expectedReferencesTable, References $actualReferences): void + private function assertReferencesMatch(TableNode $expectedReferencesTable, References $actualReferences, ContentGraphInterface $contentGraph): void { $expectedReferences = $expectedReferencesTable->getHash(); Assert::assertSame( @@ -480,7 +481,7 @@ private function assertReferencesMatch(TableNode $expectedReferencesTable, Refer $actualReferences[$index]->name->value ); $expectedReferenceDiscriminator = NodeDiscriminator::fromShorthand($row['Node']); - $actualReferenceDiscriminator = NodeDiscriminator::fromNode($actualReferences[$index]->node); + $actualReferenceDiscriminator = NodeDiscriminator::fromNodeAndContentGraph($actualReferences[$index]->node, $contentGraph); Assert::assertTrue( $expectedReferenceDiscriminator->equals($actualReferenceDiscriminator), 'Reference discriminator does not match.' From 313656ce5959dbfd85c699f641941dcb65e1e576 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 16 Jun 2024 21:08:43 +0200 Subject: [PATCH 2/3] TASK: Introduce NodeWithContentStreamId for testing We cannot rely on $this->currentContentStreamId being the matching one for $this->currentNode, because the step `I expect a node identified by live-cs-identifier;lady-eleonode-nodesworth;{} to exist in the content graph` can initialize a foreign node! --- .../Bootstrap/CRTestSuiteRuntimeVariables.php | 16 +++++- .../Bootstrap/Features/NodeCopying.php | 2 +- .../Bootstrap/Helpers/NodeDiscriminator.php | 31 +++++----- .../Helpers/NodeWithContentStreamId.php | 29 ++++++++++ .../Features/Bootstrap/ProjectedNodeTrait.php | 57 +++++++++++-------- 5 files changed, 90 insertions(+), 45 deletions(-) create mode 100644 Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeWithContentStreamId.php diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php index 6642d015bf7..9f54f1decaf 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php @@ -19,7 +19,6 @@ use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint; use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface; -use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate; use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath; use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; @@ -30,6 +29,8 @@ use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\FakeClock; use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\FakeUserIdProvider; +use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\NodeWithContentStreamId; +use PHPUnit\Framework\Assert; /** * The node creation trait for behavioral tests @@ -50,7 +51,11 @@ trait CRTestSuiteRuntimeVariables protected ?\Exception $lastCommandException = null; - protected ?Node $currentNode = null; + /** + * The Node's content stream id doesn't necessarily have to match with {@see $currentContentStreamId} if the node was initialized via the content graph from another workspace + * thus we have to track it as well. + */ + protected ?NodeWithContentStreamId $currentNode = null; protected ?NodeAggregate $currentNodeAggregate = null; @@ -182,7 +187,12 @@ public function iRememberNodeAggregateIdOfNodesChildAs(string $parentNodeAggrega protected function getCurrentNodeAggregateId(): NodeAggregateId { - assert($this->currentNode instanceof Node); + $this->expectCurrentNode(); return $this->currentNode->aggregateId; } + + protected function expectCurrentNode(): void + { + Assert::assertNotNull($this->currentNode, 'No current node present'); + } } diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeCopying.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeCopying.php index 6c68de67e35..a51e3d0b87b 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeCopying.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeCopying.php @@ -59,7 +59,7 @@ public function theCommandCopyNodesRecursivelyIsExecutedCopyingTheCurrentNodeAgg $command = CopyNodesRecursively::createFromSubgraphAndStartNode( $subgraph, $workspaceName, - $this->currentNode, + $this->currentNode->instance, $targetDimensionSpacePoint, NodeAggregateId::fromString($commandArguments['targetParentNodeAggregateId']), $targetSucceedingSiblingNodeAggregateId, diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php index 8539c8c4cf5..934a48899c6 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php @@ -37,6 +37,15 @@ private function __construct( ) { } + public static function create(ContentStreamId $contentStreamId, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateId $aggregateId): self + { + return new self( + $contentStreamId, + $aggregateId, + $originDimensionSpacePoint + ); + } + public static function fromShorthand(string $shorthand): self { list($contentStreamId, $nodeAggregateId, $originDimensionSpacePoint) = explode(';', $shorthand); @@ -48,26 +57,12 @@ public static function fromShorthand(string $shorthand): self ); } - /** @deprecated will be removed */ - public static function fromNode(Node $node): self + public static function fromNode(NodeWithContentStreamId $decorated): self { return new self( - $node->subgraphIdentity->contentStreamId, - $node->aggregateId, - $node->originDimensionSpacePoint - ); - } - - public static function fromNodeAndContentGraph(Node $node, ContentGraphInterface $contentGraph): self - { - if (!$node->workspaceName->equals($contentGraph->getWorkspaceName())) { - throw new \InvalidArgumentException(sprintf('Expected nodes workspace %s to match given subgraph workspace %s.', $node->workspaceName->value, $contentGraph->getWorkspaceName()->value), 1718554466); - } - - return new self( - $contentGraph->getContentStreamId(), - $node->aggregateId, - $node->originDimensionSpacePoint + $decorated->contentStreamId, + $decorated->instance->aggregateId, + $decorated->instance->originDimensionSpacePoint ); } diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeWithContentStreamId.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeWithContentStreamId.php new file mode 100644 index 00000000000..aa58916ce0b --- /dev/null +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeWithContentStreamId.php @@ -0,0 +1,29 @@ +aggregateId, $node, $contentStreamId); + } + + public function withNode(Node $node): self + { + return new self($node->aggregateId, $node, $this->contentStreamId); + } +} diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php index 3eeb6cbc538..b772bd428b5 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php @@ -33,10 +33,12 @@ use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\ContentRepository\Core\SharedModel\Node\PropertyName; +use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\ContentRepository\Core\Tests\Behavior\Fixtures\DayOfWeek; use Neos\ContentRepository\Core\Tests\Behavior\Fixtures\PostalAddress; use Neos\ContentRepository\Core\Tests\Behavior\Fixtures\PriceSpecification; use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\NodeDiscriminator; +use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\NodeWithContentStreamId; use PHPUnit\Framework\Assert; /** @@ -96,7 +98,8 @@ public function iExpectANodeIdentifiedByXToExistInTheContentGraph(string $serial . '" and originating in dimension space point "' . $nodeDiscriminator->originDimensionSpacePoint->toJson() . '" was not found in content stream "' . $nodeDiscriminator->contentStreamId->value . '"' ); - $this->currentNode = $currentNodeAggregate->getNodeByOccupiedDimensionSpacePoint($nodeDiscriminator->originDimensionSpacePoint); + $node = $currentNodeAggregate->getNodeByOccupiedDimensionSpacePoint($nodeDiscriminator->originDimensionSpacePoint); + $this->currentNode = NodeWithContentStreamId::create($node, $nodeDiscriminator->contentStreamId); } /** @@ -108,10 +111,10 @@ public function iExpectNodeAggregateIdToLeadToNode( ): void { $nodeAggregateId = NodeAggregateId::fromString($serializedNodeAggregateId); $expectedDiscriminator = NodeDiscriminator::fromShorthand($serializedNodeDiscriminator); - $this->initializeCurrentNodeFromContentSubgraph(function (ContentSubgraphInterface $subgraph) use ($nodeAggregateId, $expectedDiscriminator) { + $this->initializeCurrentNodeFromContentSubgraph(function (ContentSubgraphInterface $subgraph, ContentStreamId $currentContentStreamId) use ($nodeAggregateId, $expectedDiscriminator) { $currentNode = $subgraph->findNodeById($nodeAggregateId); Assert::assertNotNull($currentNode, 'No node could be found by node aggregate id "' . $nodeAggregateId->value . '" in content subgraph "' . $this->currentDimensionSpacePoint->toJson() . '@' . $this->currentWorkspaceName->value . '"'); - $actualDiscriminator = NodeDiscriminator::fromNode($currentNode); + $actualDiscriminator = NodeDiscriminator::create($currentContentStreamId, $currentNode->originDimensionSpacePoint, $currentNode->aggregateId); Assert::assertTrue($expectedDiscriminator->equals($actualDiscriminator), 'Node discriminators do not match. Expected was ' . json_encode($expectedDiscriminator) . ' , given was ' . json_encode($actualDiscriminator)); return $currentNode; }); @@ -145,10 +148,10 @@ public function iExpectPathToLeadToNode(string $serializedNodePath, string $seri } $nodePath = NodePath::fromString($serializedNodePath); $expectedDiscriminator = NodeDiscriminator::fromShorthand($serializedNodeDiscriminator); - $this->initializeCurrentNodeFromContentSubgraph(function (ContentSubgraphInterface $subgraph) use ($nodePath, $expectedDiscriminator) { + $this->initializeCurrentNodeFromContentSubgraph(function (ContentSubgraphInterface $subgraph, ContentStreamId $currentContentStreamId) use ($nodePath, $expectedDiscriminator) { $currentNode = $subgraph->findNodeByPath($nodePath, $this->getRootNodeAggregateId()); Assert::assertNotNull($currentNode, 'No node could be found by node path "' . $nodePath->serializeToString() . '" in content subgraph "' . $this->currentDimensionSpacePoint->toJson() . '@' . $this->currentWorkspaceName->value . '"'); - $actualDiscriminator = NodeDiscriminator::fromNode($currentNode); + $actualDiscriminator = NodeDiscriminator::create($currentContentStreamId, $currentNode->originDimensionSpacePoint, $currentNode->aggregateId); Assert::assertTrue($expectedDiscriminator->equals($actualDiscriminator), 'Node discriminators do not match. Expected was ' . json_encode($expectedDiscriminator) . ' , given was ' . json_encode($actualDiscriminator)); return $currentNode; }); @@ -275,9 +278,16 @@ public function iExpectThisNodeToExactlyInheritTheTags(string $expectedTagList): }); } + /** + * @param callable(ContentSubgraphInterface $subgraph, ContentStreamId $currentContentStreamId): Node $query + */ protected function initializeCurrentNodeFromContentSubgraph(callable $query): void { - $this->currentNode = $query($this->getCurrentSubgraph()); + $contentGraph = $this->getCurrentContentGraph(); + $node = $query($this->getCurrentSubgraph($contentGraph), $contentGraph->getContentStreamId()); + $this->currentNode = NodeWithContentStreamId::create( + $node, $contentGraph->getContentStreamId() + ); } /** @@ -457,15 +467,15 @@ public function iExpectThisNodeToHaveNoReferences(): void public function iExpectThisNodeToBeReferencedBy(TableNode $expectedReferences): void { $contentGraph = $this->getCurrentContentGraph(); - $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedReferences, $contentGraph) { + $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedReferences, $contentGraph) { $actualReferences = $this->getCurrentSubgraph($contentGraph) ->findBackReferences($currentNode->aggregateId, FindBackReferencesFilter::create()); - $this->assertReferencesMatch($expectedReferences, $actualReferences, $contentGraph); + $this->assertReferencesMatch($expectedReferences, $actualReferences, $currentNode->contentStreamId); }); } - private function assertReferencesMatch(TableNode $expectedReferencesTable, References $actualReferences, ContentGraphInterface $contentGraph): void + private function assertReferencesMatch(TableNode $expectedReferencesTable, References $actualReferences, ContentStreamId $actualContentStreamId): void { $expectedReferences = $expectedReferencesTable->getHash(); Assert::assertSame( @@ -481,7 +491,7 @@ private function assertReferencesMatch(TableNode $expectedReferencesTable, Refer $actualReferences[$index]->name->value ); $expectedReferenceDiscriminator = NodeDiscriminator::fromShorthand($row['Node']); - $actualReferenceDiscriminator = NodeDiscriminator::fromNodeAndContentGraph($actualReferences[$index]->node, $contentGraph); + $actualReferenceDiscriminator = NodeDiscriminator::create($actualContentStreamId, $actualReferences[$index]->node->originDimensionSpacePoint, $actualReferences[$index]->node->aggregateId); Assert::assertTrue( $expectedReferenceDiscriminator->equals($actualReferenceDiscriminator), 'Reference discriminator does not match.' @@ -550,17 +560,17 @@ public function iExpectThisNodeToNotBeReferenced(): void public function iExpectThisNodeToBeTheChildOfNode(string $serializedParentNodeDiscriminator): void { $expectedParentDiscriminator = NodeDiscriminator::fromShorthand($serializedParentNodeDiscriminator); - $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedParentDiscriminator) { + $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedParentDiscriminator) { $subgraph = $this->getCurrentSubgraph(); $parent = $subgraph->findParentNode($currentNode->aggregateId); Assert::assertInstanceOf(Node::class, $parent, 'Parent not found.'); - $actualParentDiscriminator = NodeDiscriminator::fromNode($parent); + $actualParentDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($parent)); Assert::assertTrue($expectedParentDiscriminator->equals($actualParentDiscriminator), 'Parent discriminator does not match. Expected was ' . json_encode($expectedParentDiscriminator) . ', given was ' . json_encode($actualParentDiscriminator)); $expectedChildDiscriminator = NodeDiscriminator::fromNode($currentNode); - $child = $subgraph->findNodeByPath($currentNode->name, $parent->aggregateId); - $actualChildDiscriminator = NodeDiscriminator::fromNode($child); + $child = $subgraph->findNodeByPath($currentNode->instance->name, $parent->aggregateId); + $actualChildDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($child)); Assert::assertTrue($expectedChildDiscriminator->equals($actualChildDiscriminator), 'Child discriminator does not match. Expected was ' . json_encode($expectedChildDiscriminator) . ', given was ' . json_encode($actualChildDiscriminator)); }); } @@ -583,7 +593,7 @@ public function iExpectThisNodeToHaveNoParentNode(): void */ public function iExpectThisNodeToHaveTheFollowingChildNodes(TableNode $expectedChildNodesTable): void { - $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedChildNodesTable) { + $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedChildNodesTable) { $subgraph = $this->getCurrentSubgraph(); $actualChildNodes = []; foreach ($subgraph->findChildNodes($currentNode->aggregateId, FindChildNodesFilter::create()) as $actualChildNode) { @@ -598,7 +608,7 @@ public function iExpectThisNodeToHaveTheFollowingChildNodes(TableNode $expectedC Assert::assertTrue($expectedNodeName->equals($actualNodeName), 'ContentSubgraph::findChildNodes: Node name in index ' . $index . ' does not match. Expected: "' . $expectedNodeName->value . '" Actual: "' . $actualNodeName->value . '"'); if (isset($row['NodeDiscriminator'])) { $expectedNodeDiscriminator = NodeDiscriminator::fromShorthand($row['NodeDiscriminator']); - $actualNodeDiscriminator = NodeDiscriminator::fromNode($actualChildNodes[$index]); + $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($actualChildNodes[$index])); Assert::assertTrue($expectedNodeDiscriminator->equals($actualNodeDiscriminator), 'ContentSubgraph::findChildNodes: Node discriminator in index ' . $index . ' does not match. Expected: ' . json_encode($expectedNodeDiscriminator->jsonSerialize()) . ' Actual: ' . json_encode($actualNodeDiscriminator)); } } @@ -624,7 +634,7 @@ public function iExpectThisNodeToHaveNoChildNodes(): void */ public function iExpectThisNodeToHaveTheFollowingPrecedingSiblings(TableNode $expectedPrecedingSiblingsTable): void { - $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedPrecedingSiblingsTable) { + $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedPrecedingSiblingsTable) { $actualSiblings = []; foreach ( $this->getCurrentSubgraph()->findPrecedingSiblingNodes( @@ -637,7 +647,7 @@ public function iExpectThisNodeToHaveTheFollowingPrecedingSiblings(TableNode $ex Assert::assertCount(count($expectedPrecedingSiblingsTable->getHash()), $actualSiblings, 'ContentSubgraph::findPrecedingSiblingNodes: Sibling count does not match'); foreach ($expectedPrecedingSiblingsTable->getHash() as $index => $row) { $expectedNodeDiscriminator = NodeDiscriminator::fromShorthand($row['NodeDiscriminator']); - $actualNodeDiscriminator = NodeDiscriminator::fromNode($actualSiblings[$index]); + $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($actualSiblings[$index])); Assert::assertTrue($expectedNodeDiscriminator->equals($actualNodeDiscriminator), 'ContentSubgraph::findPrecedingSiblingNodes: Node discriminator in index ' . $index . ' does not match. Expected: ' . json_encode($expectedNodeDiscriminator) . ' Actual: ' . json_encode($actualNodeDiscriminator)); } }); @@ -661,7 +671,7 @@ public function iExpectThisNodeToHaveNoPrecedingSiblings(): void */ public function iExpectThisNodeToHaveTheFollowingSucceedingSiblings(TableNode $expectedSucceedingSiblingsTable): void { - $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedSucceedingSiblingsTable) { + $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedSucceedingSiblingsTable) { $actualSiblings = []; foreach ( $this->getCurrentSubgraph()->findSucceedingSiblingNodes( @@ -674,7 +684,7 @@ public function iExpectThisNodeToHaveTheFollowingSucceedingSiblings(TableNode $e Assert::assertCount(count($expectedSucceedingSiblingsTable->getHash()), $actualSiblings, 'ContentSubgraph::findSucceedingSiblingNodes: Sibling count does not match'); foreach ($expectedSucceedingSiblingsTable->getHash() as $index => $row) { $expectedNodeDiscriminator = NodeDiscriminator::fromShorthand($row['NodeDiscriminator']); - $actualNodeDiscriminator = NodeDiscriminator::fromNode($actualSiblings[$index]); + $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($actualSiblings[$index])); Assert::assertTrue($expectedNodeDiscriminator->equals($actualNodeDiscriminator), 'ContentSubgraph::findSucceedingSiblingNodes: Node discriminator in index ' . $index . ' does not match. Expected: ' . json_encode($expectedNodeDiscriminator) . ' Actual: ' . json_encode($actualNodeDiscriminator)); } }); @@ -692,14 +702,15 @@ public function iExpectThisNodeToHaveNoSucceedingSiblings(): void }); } - protected function assertOnCurrentNode(callable $assertions): void + protected function assertOnCurrentNodeWithContentStreamId(callable $assertions): void { $this->expectCurrentNode(); $assertions($this->currentNode); } - protected function expectCurrentNode(): void + protected function assertOnCurrentNode(callable $assertions): void { - Assert::assertNotNull($this->currentNode, 'No current node present'); + $this->expectCurrentNode(); + $assertions($this->currentNode->instance); } } From eef416659f9cf54d3c34971bee6e9c3ecfd1cbc6 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 16 Jun 2024 21:23:22 +0200 Subject: [PATCH 3/3] TASK: Introduce `ContentStreamAwareNodeBuilder` to simplify creating `ContentStreamAwareNode` --- .../Bootstrap/CRTestSuiteRuntimeVariables.php | 8 +-- .../Bootstrap/Features/NodeCopying.php | 2 +- ...treamId.php => ContentStreamAwareNode.php} | 15 ++--- .../Helpers/ContentStreamAwareNodeBuilder.php | 26 ++++++++ .../Bootstrap/Helpers/NodeDiscriminator.php | 17 ++--- .../Features/Bootstrap/ProjectedNodeTrait.php | 63 ++++++++++--------- 6 files changed, 76 insertions(+), 55 deletions(-) rename Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/{NodeWithContentStreamId.php => ContentStreamAwareNode.php} (52%) create mode 100644 Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/ContentStreamAwareNodeBuilder.php diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php index 9f54f1decaf..520f031a637 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php @@ -29,7 +29,7 @@ use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\FakeClock; use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\FakeUserIdProvider; -use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\NodeWithContentStreamId; +use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\ContentStreamAwareNode; use PHPUnit\Framework\Assert; /** @@ -55,7 +55,7 @@ trait CRTestSuiteRuntimeVariables * The Node's content stream id doesn't necessarily have to match with {@see $currentContentStreamId} if the node was initialized via the content graph from another workspace * thus we have to track it as well. */ - protected ?NodeWithContentStreamId $currentNode = null; + protected ?ContentStreamAwareNode $currentNode = null; protected ?NodeAggregate $currentNodeAggregate = null; @@ -166,9 +166,9 @@ public function getCurrentContentGraph(): ContentGraphInterface return $contentGraphFinder->getByWorkspaceName($this->currentWorkspaceName); } - public function getCurrentSubgraph(?ContentGraphInterface $contentGraphToUse = null): ContentSubgraphInterface + public function getCurrentSubgraph(): ContentSubgraphInterface { - return ($contentGraphToUse ?? $this->getCurrentContentGraph())->getSubgraph( + return $this->getCurrentContentGraph()->getSubgraph( $this->currentDimensionSpacePoint, $this->currentVisibilityConstraints ); diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeCopying.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeCopying.php index a51e3d0b87b..3122c2501f9 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeCopying.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeCopying.php @@ -59,7 +59,7 @@ public function theCommandCopyNodesRecursivelyIsExecutedCopyingTheCurrentNodeAgg $command = CopyNodesRecursively::createFromSubgraphAndStartNode( $subgraph, $workspaceName, - $this->currentNode->instance, + $this->currentNode->nodeInstance, $targetDimensionSpacePoint, NodeAggregateId::fromString($commandArguments['targetParentNodeAggregateId']), $targetSucceedingSiblingNodeAggregateId, diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeWithContentStreamId.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/ContentStreamAwareNode.php similarity index 52% rename from Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeWithContentStreamId.php rename to Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/ContentStreamAwareNode.php index aa58916ce0b..691b0e72dca 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeWithContentStreamId.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/ContentStreamAwareNode.php @@ -8,22 +8,23 @@ use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; -final readonly class NodeWithContentStreamId +final readonly class ContentStreamAwareNode { private function __construct( - public NodeAggregateId $aggregateId, - public Node $instance, public ContentStreamId $contentStreamId, + public Node $nodeInstance, + /** Alias for $currentNode->instance->aggregateId */ + public NodeAggregateId $aggregateId, ) { } - public static function create(Node $node, ContentStreamId $contentStreamId): self + public static function create(ContentStreamId $contentStreamId, Node $node): self { - return new self($node->aggregateId, $node, $contentStreamId); + return new self($contentStreamId, $node, $node->aggregateId); } - public function withNode(Node $node): self + public function builder(): ContentStreamAwareNodeBuilder { - return new self($node->aggregateId, $node, $this->contentStreamId); + return ContentStreamAwareNodeBuilder::create($this->contentStreamId); } } diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/ContentStreamAwareNodeBuilder.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/ContentStreamAwareNodeBuilder.php new file mode 100644 index 00000000000..86a5d1bbef2 --- /dev/null +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/ContentStreamAwareNodeBuilder.php @@ -0,0 +1,26 @@ +contentStreamId, $node); + } +} diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php index 934a48899c6..c39488aec8b 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php @@ -37,15 +37,6 @@ private function __construct( ) { } - public static function create(ContentStreamId $contentStreamId, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateId $aggregateId): self - { - return new self( - $contentStreamId, - $aggregateId, - $originDimensionSpacePoint - ); - } - public static function fromShorthand(string $shorthand): self { list($contentStreamId, $nodeAggregateId, $originDimensionSpacePoint) = explode(';', $shorthand); @@ -57,12 +48,12 @@ public static function fromShorthand(string $shorthand): self ); } - public static function fromNode(NodeWithContentStreamId $decorated): self + public static function fromNode(ContentStreamAwareNode $contentStreamAwareNode): self { return new self( - $decorated->contentStreamId, - $decorated->instance->aggregateId, - $decorated->instance->originDimensionSpacePoint + $contentStreamAwareNode->contentStreamId, + $contentStreamAwareNode->nodeInstance->aggregateId, + $contentStreamAwareNode->nodeInstance->originDimensionSpacePoint ); } diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php index b772bd428b5..56bc9d46bf3 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php @@ -38,7 +38,8 @@ use Neos\ContentRepository\Core\Tests\Behavior\Fixtures\PostalAddress; use Neos\ContentRepository\Core\Tests\Behavior\Fixtures\PriceSpecification; use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\NodeDiscriminator; -use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\NodeWithContentStreamId; +use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\ContentStreamAwareNode; +use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\ContentStreamAwareNodeBuilder; use PHPUnit\Framework\Assert; /** @@ -99,7 +100,7 @@ public function iExpectANodeIdentifiedByXToExistInTheContentGraph(string $serial . '" was not found in content stream "' . $nodeDiscriminator->contentStreamId->value . '"' ); $node = $currentNodeAggregate->getNodeByOccupiedDimensionSpacePoint($nodeDiscriminator->originDimensionSpacePoint); - $this->currentNode = NodeWithContentStreamId::create($node, $nodeDiscriminator->contentStreamId); + $this->currentNode = ContentStreamAwareNode::create($nodeDiscriminator->contentStreamId, $node); } /** @@ -111,10 +112,10 @@ public function iExpectNodeAggregateIdToLeadToNode( ): void { $nodeAggregateId = NodeAggregateId::fromString($serializedNodeAggregateId); $expectedDiscriminator = NodeDiscriminator::fromShorthand($serializedNodeDiscriminator); - $this->initializeCurrentNodeFromContentSubgraph(function (ContentSubgraphInterface $subgraph, ContentStreamId $currentContentStreamId) use ($nodeAggregateId, $expectedDiscriminator) { + $this->initializeCurrentNodeFromContentSubgraph(function (ContentSubgraphInterface $subgraph, ContentStreamAwareNodeBuilder $contentStreamAwareNodeBuilder) use ($nodeAggregateId, $expectedDiscriminator) { $currentNode = $subgraph->findNodeById($nodeAggregateId); Assert::assertNotNull($currentNode, 'No node could be found by node aggregate id "' . $nodeAggregateId->value . '" in content subgraph "' . $this->currentDimensionSpacePoint->toJson() . '@' . $this->currentWorkspaceName->value . '"'); - $actualDiscriminator = NodeDiscriminator::create($currentContentStreamId, $currentNode->originDimensionSpacePoint, $currentNode->aggregateId); + $actualDiscriminator = NodeDiscriminator::fromNode($contentStreamAwareNodeBuilder->buildNode($currentNode)); Assert::assertTrue($expectedDiscriminator->equals($actualDiscriminator), 'Node discriminators do not match. Expected was ' . json_encode($expectedDiscriminator) . ' , given was ' . json_encode($actualDiscriminator)); return $currentNode; }); @@ -148,10 +149,10 @@ public function iExpectPathToLeadToNode(string $serializedNodePath, string $seri } $nodePath = NodePath::fromString($serializedNodePath); $expectedDiscriminator = NodeDiscriminator::fromShorthand($serializedNodeDiscriminator); - $this->initializeCurrentNodeFromContentSubgraph(function (ContentSubgraphInterface $subgraph, ContentStreamId $currentContentStreamId) use ($nodePath, $expectedDiscriminator) { + $this->initializeCurrentNodeFromContentSubgraph(function (ContentSubgraphInterface $subgraph, ContentStreamAwareNodeBuilder $contentStreamAwareNodeBuilder) use ($nodePath, $expectedDiscriminator) { $currentNode = $subgraph->findNodeByPath($nodePath, $this->getRootNodeAggregateId()); Assert::assertNotNull($currentNode, 'No node could be found by node path "' . $nodePath->serializeToString() . '" in content subgraph "' . $this->currentDimensionSpacePoint->toJson() . '@' . $this->currentWorkspaceName->value . '"'); - $actualDiscriminator = NodeDiscriminator::create($currentContentStreamId, $currentNode->originDimensionSpacePoint, $currentNode->aggregateId); + $actualDiscriminator = NodeDiscriminator::fromNode($contentStreamAwareNodeBuilder->buildNode($currentNode)); Assert::assertTrue($expectedDiscriminator->equals($actualDiscriminator), 'Node discriminators do not match. Expected was ' . json_encode($expectedDiscriminator) . ' , given was ' . json_encode($actualDiscriminator)); return $currentNode; }); @@ -279,15 +280,18 @@ public function iExpectThisNodeToExactlyInheritTheTags(string $expectedTagList): } /** - * @param callable(ContentSubgraphInterface $subgraph, ContentStreamId $currentContentStreamId): Node $query + * @param callable(ContentSubgraphInterface $subgraph, ContentStreamAwareNodeBuilder $contentStreamAwareNodeBuilder): Node $query */ protected function initializeCurrentNodeFromContentSubgraph(callable $query): void { $contentGraph = $this->getCurrentContentGraph(); - $node = $query($this->getCurrentSubgraph($contentGraph), $contentGraph->getContentStreamId()); - $this->currentNode = NodeWithContentStreamId::create( - $node, $contentGraph->getContentStreamId() + $subgraph = $contentGraph->getSubgraph( + $this->currentDimensionSpacePoint, + $this->currentVisibilityConstraints ); + $contentStreamAwareNodeBuilder = ContentStreamAwareNodeBuilder::create($contentGraph->getContentStreamId()); + $node = $query($subgraph, $contentStreamAwareNodeBuilder); + $this->currentNode = $contentStreamAwareNodeBuilder->buildNode($node); } /** @@ -438,11 +442,11 @@ public function iExpectThisNodeToHaveNoProperties(): void */ public function iExpectThisNodeToHaveTheFollowingReferences(TableNode $expectedReferences): void { - $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedReferences) { + $this->assertOnCurrentContentStreamAwareNode(function (ContentStreamAwareNode $currentNode) use ($expectedReferences) { $actualReferences = $this->getCurrentSubgraph() ->findReferences($currentNode->aggregateId, FindReferencesFilter::create()); - $this->assertReferencesMatch($expectedReferences, $actualReferences); + $this->assertReferencesMatch($expectedReferences, $actualReferences, $currentNode->builder()); }); } @@ -466,16 +470,15 @@ public function iExpectThisNodeToHaveNoReferences(): void */ public function iExpectThisNodeToBeReferencedBy(TableNode $expectedReferences): void { - $contentGraph = $this->getCurrentContentGraph(); - $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedReferences, $contentGraph) { - $actualReferences = $this->getCurrentSubgraph($contentGraph) + $this->assertOnCurrentContentStreamAwareNode(function (ContentStreamAwareNode $currentNode) use ($expectedReferences) { + $actualReferences = $this->getCurrentSubgraph() ->findBackReferences($currentNode->aggregateId, FindBackReferencesFilter::create()); - $this->assertReferencesMatch($expectedReferences, $actualReferences, $currentNode->contentStreamId); + $this->assertReferencesMatch($expectedReferences, $actualReferences, $currentNode->builder()); }); } - private function assertReferencesMatch(TableNode $expectedReferencesTable, References $actualReferences, ContentStreamId $actualContentStreamId): void + private function assertReferencesMatch(TableNode $expectedReferencesTable, References $actualReferences, ContentStreamAwareNodeBuilder $contentStreamAwareNodeBuilder): void { $expectedReferences = $expectedReferencesTable->getHash(); Assert::assertSame( @@ -491,7 +494,7 @@ private function assertReferencesMatch(TableNode $expectedReferencesTable, Refer $actualReferences[$index]->name->value ); $expectedReferenceDiscriminator = NodeDiscriminator::fromShorthand($row['Node']); - $actualReferenceDiscriminator = NodeDiscriminator::create($actualContentStreamId, $actualReferences[$index]->node->originDimensionSpacePoint, $actualReferences[$index]->node->aggregateId); + $actualReferenceDiscriminator = NodeDiscriminator::fromNode($contentStreamAwareNodeBuilder->buildNode($actualReferences[$index]->node)); Assert::assertTrue( $expectedReferenceDiscriminator->equals($actualReferenceDiscriminator), 'Reference discriminator does not match.' @@ -560,17 +563,17 @@ public function iExpectThisNodeToNotBeReferenced(): void public function iExpectThisNodeToBeTheChildOfNode(string $serializedParentNodeDiscriminator): void { $expectedParentDiscriminator = NodeDiscriminator::fromShorthand($serializedParentNodeDiscriminator); - $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedParentDiscriminator) { + $this->assertOnCurrentContentStreamAwareNode(function (ContentStreamAwareNode $currentNode) use ($expectedParentDiscriminator) { $subgraph = $this->getCurrentSubgraph(); $parent = $subgraph->findParentNode($currentNode->aggregateId); Assert::assertInstanceOf(Node::class, $parent, 'Parent not found.'); - $actualParentDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($parent)); + $actualParentDiscriminator = NodeDiscriminator::fromNode($currentNode->builder()->buildNode($parent)); Assert::assertTrue($expectedParentDiscriminator->equals($actualParentDiscriminator), 'Parent discriminator does not match. Expected was ' . json_encode($expectedParentDiscriminator) . ', given was ' . json_encode($actualParentDiscriminator)); $expectedChildDiscriminator = NodeDiscriminator::fromNode($currentNode); - $child = $subgraph->findNodeByPath($currentNode->instance->name, $parent->aggregateId); - $actualChildDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($child)); + $child = $subgraph->findNodeByPath($currentNode->nodeInstance->name, $parent->aggregateId); + $actualChildDiscriminator = NodeDiscriminator::fromNode($currentNode->builder()->buildNode($child)); Assert::assertTrue($expectedChildDiscriminator->equals($actualChildDiscriminator), 'Child discriminator does not match. Expected was ' . json_encode($expectedChildDiscriminator) . ', given was ' . json_encode($actualChildDiscriminator)); }); } @@ -593,7 +596,7 @@ public function iExpectThisNodeToHaveNoParentNode(): void */ public function iExpectThisNodeToHaveTheFollowingChildNodes(TableNode $expectedChildNodesTable): void { - $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedChildNodesTable) { + $this->assertOnCurrentContentStreamAwareNode(function (ContentStreamAwareNode $currentNode) use ($expectedChildNodesTable) { $subgraph = $this->getCurrentSubgraph(); $actualChildNodes = []; foreach ($subgraph->findChildNodes($currentNode->aggregateId, FindChildNodesFilter::create()) as $actualChildNode) { @@ -608,7 +611,7 @@ public function iExpectThisNodeToHaveTheFollowingChildNodes(TableNode $expectedC Assert::assertTrue($expectedNodeName->equals($actualNodeName), 'ContentSubgraph::findChildNodes: Node name in index ' . $index . ' does not match. Expected: "' . $expectedNodeName->value . '" Actual: "' . $actualNodeName->value . '"'); if (isset($row['NodeDiscriminator'])) { $expectedNodeDiscriminator = NodeDiscriminator::fromShorthand($row['NodeDiscriminator']); - $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($actualChildNodes[$index])); + $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->builder()->buildNode($actualChildNodes[$index])); Assert::assertTrue($expectedNodeDiscriminator->equals($actualNodeDiscriminator), 'ContentSubgraph::findChildNodes: Node discriminator in index ' . $index . ' does not match. Expected: ' . json_encode($expectedNodeDiscriminator->jsonSerialize()) . ' Actual: ' . json_encode($actualNodeDiscriminator)); } } @@ -634,7 +637,7 @@ public function iExpectThisNodeToHaveNoChildNodes(): void */ public function iExpectThisNodeToHaveTheFollowingPrecedingSiblings(TableNode $expectedPrecedingSiblingsTable): void { - $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedPrecedingSiblingsTable) { + $this->assertOnCurrentContentStreamAwareNode(function (ContentStreamAwareNode $currentNode) use ($expectedPrecedingSiblingsTable) { $actualSiblings = []; foreach ( $this->getCurrentSubgraph()->findPrecedingSiblingNodes( @@ -647,7 +650,7 @@ public function iExpectThisNodeToHaveTheFollowingPrecedingSiblings(TableNode $ex Assert::assertCount(count($expectedPrecedingSiblingsTable->getHash()), $actualSiblings, 'ContentSubgraph::findPrecedingSiblingNodes: Sibling count does not match'); foreach ($expectedPrecedingSiblingsTable->getHash() as $index => $row) { $expectedNodeDiscriminator = NodeDiscriminator::fromShorthand($row['NodeDiscriminator']); - $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($actualSiblings[$index])); + $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->builder()->buildNode($actualSiblings[$index])); Assert::assertTrue($expectedNodeDiscriminator->equals($actualNodeDiscriminator), 'ContentSubgraph::findPrecedingSiblingNodes: Node discriminator in index ' . $index . ' does not match. Expected: ' . json_encode($expectedNodeDiscriminator) . ' Actual: ' . json_encode($actualNodeDiscriminator)); } }); @@ -671,7 +674,7 @@ public function iExpectThisNodeToHaveNoPrecedingSiblings(): void */ public function iExpectThisNodeToHaveTheFollowingSucceedingSiblings(TableNode $expectedSucceedingSiblingsTable): void { - $this->assertOnCurrentNodeWithContentStreamId(function (NodeWithContentStreamId $currentNode) use ($expectedSucceedingSiblingsTable) { + $this->assertOnCurrentContentStreamAwareNode(function (ContentStreamAwareNode $currentNode) use ($expectedSucceedingSiblingsTable) { $actualSiblings = []; foreach ( $this->getCurrentSubgraph()->findSucceedingSiblingNodes( @@ -684,7 +687,7 @@ public function iExpectThisNodeToHaveTheFollowingSucceedingSiblings(TableNode $e Assert::assertCount(count($expectedSucceedingSiblingsTable->getHash()), $actualSiblings, 'ContentSubgraph::findSucceedingSiblingNodes: Sibling count does not match'); foreach ($expectedSucceedingSiblingsTable->getHash() as $index => $row) { $expectedNodeDiscriminator = NodeDiscriminator::fromShorthand($row['NodeDiscriminator']); - $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->withNode($actualSiblings[$index])); + $actualNodeDiscriminator = NodeDiscriminator::fromNode($currentNode->builder()->buildNode($actualSiblings[$index])); Assert::assertTrue($expectedNodeDiscriminator->equals($actualNodeDiscriminator), 'ContentSubgraph::findSucceedingSiblingNodes: Node discriminator in index ' . $index . ' does not match. Expected: ' . json_encode($expectedNodeDiscriminator) . ' Actual: ' . json_encode($actualNodeDiscriminator)); } }); @@ -702,7 +705,7 @@ public function iExpectThisNodeToHaveNoSucceedingSiblings(): void }); } - protected function assertOnCurrentNodeWithContentStreamId(callable $assertions): void + protected function assertOnCurrentContentStreamAwareNode(callable $assertions): void { $this->expectCurrentNode(); $assertions($this->currentNode); @@ -711,6 +714,6 @@ protected function assertOnCurrentNodeWithContentStreamId(callable $assertions): protected function assertOnCurrentNode(callable $assertions): void { $this->expectCurrentNode(); - $assertions($this->currentNode->instance); + $assertions($this->currentNode->nodeInstance); } }