Skip to content

Commit

Permalink
TASK: Introduce ContentStreamAwareNodeBuilder to simplify creating …
Browse files Browse the repository at this point in the history
…`ContentStreamAwareNode`
  • Loading branch information
mhsdesign committed Jun 17, 2024
1 parent 313656c commit eef4166
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;

Expand Down Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function theCommandCopyNodesRecursivelyIsExecutedCopyingTheCurrentNodeAgg
$command = CopyNodesRecursively::createFromSubgraphAndStartNode(
$subgraph,
$workspaceName,
$this->currentNode->instance,
$this->currentNode->nodeInstance,
$targetDimensionSpacePoint,
NodeAggregateId::fromString($commandArguments['targetParentNodeAggregateId']),
$targetSucceedingSiblingNodeAggregateId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers;

use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;

final readonly class ContentStreamAwareNodeBuilder
{
private function __construct(
private ContentStreamId $contentStreamId
) {
}

public static function create(ContentStreamId $contentStreamId): self
{
return new self($contentStreamId);
}

public function buildNode(Node $node): ContentStreamAwareNode
{
return ContentStreamAwareNode::create($this->contentStreamId, $node);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
);
}

Expand Down
Loading

0 comments on commit eef4166

Please sign in to comment.