Skip to content

Commit

Permalink
5034 - Reduce usage of currentContentStreamId to a bare minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schmitt committed May 10, 2024
1 parent 19b5104 commit 8701a6f
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Feature: Create node aggregate with node
"""
And using identifier "default", I define a content repository
And I am in content repository "default"
And I am in workspace "live"
And I am user identified by "initiating-user-identifier"
And the command CreateRootWorkspace is executed with payload:
| Key | Value |
Expand All @@ -41,8 +40,7 @@ Feature: Create node aggregate with node
| workspaceDescription | "The live workspace" |
| newContentStreamId | "cs-identifier" |
And the graph projection is fully up to date
And I am in content stream "cs-identifier"
And I am in dimension space point {}
And I am in workspace "live" and dimension space point {}
And the command CreateRootNodeAggregateWithNode is executed with payload:
| Key | Value |
| nodeAggregateId | "lady-eleonode-rootford" |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ public function iAmInContentStream(string $contentStreamId): void
*/
public function iAmInWorkspace(string $workspaceName): void
{
$workspace = $this->currentContentRepository->getWorkspaceFinder()->findOneByName(WorkspaceName::fromString($workspaceName));
if ($workspace === null) {
throw new \Exception(sprintf('Workspace "%s" does not exist, projection not yet up to date?', $workspaceName), 1548149355);
}
$this->currentWorkspaceName = WorkspaceName::fromString($workspaceName);
$this->currentContentStreamId = $workspace->currentContentStreamId;
}

/**
Expand All @@ -128,6 +133,16 @@ public function iAmInDimensionSpacePoint(string $dimensionSpacePoint): void
$this->currentDimensionSpacePoint = DimensionSpacePoint::fromJsonString($dimensionSpacePoint);
}

/**
* @Given /^I am in workspace "([^"]*)" and dimension space point (.*)$/
* @throws \Exception
*/
public function iAmInWorkspaceAndDimensionSpacePoint(string $workspaceName, string $dimensionSpacePoint): void
{
$this->iAmInWorkspace($workspaceName);
$this->iAmInDimensionSpacePoint($dimensionSpacePoint);
}

/**
* @Given /^I am in content stream "([^"]*)" and dimension space point (.*)$/
*/
Expand Down Expand Up @@ -164,6 +179,7 @@ public function getCurrentSubgraph(): ContentSubgraphInterface
$contentGraphFinder = $this->currentContentRepository->projectionState(ContentGraphFinder::class);
$contentGraphFinder->forgetInstances();
if (isset($this->currentContentStreamId)) {
// 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ protected function readPayloadTable(TableNode $payloadTable): array
$propertyOrMethodName = \mb_substr($line['Value'], \mb_strlen('$this->'));
$value = match ($propertyOrMethodName) {
'currentNodeAggregateId' => $this->getCurrentNodeAggregateId()->value,
'contentStreamId' => $this->currentContentStreamId->value,
default => method_exists($this, $propertyOrMethodName) ? (string)$this->$propertyOrMethodName() : (string)$this->$propertyOrMethodName,
};
} else {
Expand Down Expand Up @@ -287,7 +286,13 @@ public function theContentStreamHasState(string $contentStreamId, string $expect
*/
public function theCurrentContentStreamHasState(string $expectedState): void
{
$this->theContentStreamHasState($this->currentContentStreamId->value, $expectedState);
$this->theContentStreamHasState(
$this->currentContentRepository
->getWorkspaceFinder()
->findOneByName($this->currentWorkspaceName)
->currentContentStreamId->value,
$expectedState
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ abstract protected function readPayloadTable(TableNode $payloadTable): array;
public function theCommandCloseContentStreamIsExecutedWithPayload(TableNode $payloadTable): void
{
$commandArguments = $this->readPayloadTable($payloadTable);
$contentStreamId = isset($commandArguments['contentStreamId'])
? ContentStreamId::fromString($commandArguments['contentStreamId'])
: $this->currentContentStreamId;

$command = CloseContentStream::create($contentStreamId);
$command = CloseContentStream::create(ContentStreamId::fromString($commandArguments['contentStreamId']));

$this->lastCommandOrEventResult = $this->currentContentRepository->handle($command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ abstract protected function readPayloadTable(TableNode $payloadTable): array;
public function theCommandForkContentStreamIsExecutedWithPayload(TableNode $payloadTable): void
{
$commandArguments = $this->readPayloadTable($payloadTable);
$sourceContentStreamId = isset($commandArguments['sourceContentStreamId'])
? ContentStreamId::fromString($commandArguments['sourceContentStreamId'])
: $this->currentContentStreamId;

$command = ForkContentStream::create(
ContentStreamId::fromString($commandArguments['contentStreamId']),
$sourceContentStreamId,
ContentStreamId::fromString($commandArguments['sourceContentStreamId']),
);

$this->lastCommandOrEventResult = $this->currentContentRepository->handle($command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ public function theCommandCreateRootNodeAggregateWithNodeIsExecutedWithPayloadAn
public function theEventRootNodeAggregateWithNodeWasCreatedWasPublishedToStreamWithPayload(TableNode $payloadTable)
{
$eventPayload = $this->readPayloadTable($payloadTable);
if (!isset($eventPayload['contentStreamId'])) {
$eventPayload['contentStreamId'] = $this->currentContentStreamId?->value;
}
$contentStreamId = ContentStreamId::fromString($eventPayload['contentStreamId']);
$nodeAggregateId = NodeAggregateId::fromString($eventPayload['nodeAggregateId']);
$streamName = ContentStreamEventStreamName::fromContentStreamId($contentStreamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public function theCommandSetPropertiesIsExecutedWithPayloadAndExceptionsAreCaug
public function theEventNodePropertiesWereSetWasPublishedWithPayload(TableNode $payloadTable)
{
$eventPayload = $this->readPayloadTable($payloadTable);
if (!isset($eventPayload['contentStreamId'])) {
$eventPayload['contentStreamId'] = $this->currentContentStreamId->value;
}
if (!isset($eventPayload['originDimensionSpacePoint'])) {
$eventPayload['originDimensionSpacePoint'] = json_encode($this->currentDimensionSpacePoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ public function theCommandMoveNodeIsExecutedWithPayloadAndExceptionsAreCaught(Ta
public function theEventNodeAggregateWasMovedWasPublishedWithPayload(TableNode $payloadTable)
{
$eventPayload = $this->readPayloadTable($payloadTable);
if (!isset($eventPayload['contentStreamId'])) {
$eventPayload['contentStreamId'] = $this->currentContentStreamId->value;
}
$contentStreamId = ContentStreamId::fromString($eventPayload['contentStreamId']);
$streamName = ContentStreamEventStreamName::fromContentStreamId($contentStreamId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ public function theCommandSetNodeReferencesIsExecutedWithPayloadAndExceptionsAre
public function theEventNodeReferencesWereSetWasPublishedWithPayload(TableNode $payloadTable)
{
$eventPayload = $this->readPayloadTable($payloadTable);
if (!isset($eventPayload['contentStreamId'])) {
$eventPayload['contentStreamId'] = $this->currentContentStreamId;
}
$contentStreamId = ContentStreamId::fromString($eventPayload['contentStreamId']);
$streamName = ContentStreamEventStreamName::fromContentStreamId(
$contentStreamId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public function theCommandRemoveNodeAggregateIsExecutedWithPayloadAndExceptionsA
public function theEventNodeAggregateWasRemovedWasPublishedWithPayload(TableNode $payloadTable)
{
$eventPayload = $this->readPayloadTable($payloadTable);
if (!isset($eventPayload['contentStreamId'])) {
$eventPayload['contentStreamId'] = $this->currentContentStreamId->value;
}
$contentStreamId = ContentStreamId::fromString($eventPayload['contentStreamId']);
$streamName = ContentStreamEventStreamName::fromContentStreamId($contentStreamId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ public function theEventSubtreeWasTaggedWasPublishedWithPayload(TableNode $paylo
{
$eventPayload = $this->readPayloadTable($payloadTable);
$streamName = ContentStreamEventStreamName::fromContentStreamId(
array_key_exists('contentStreamId', $eventPayload)
? ContentStreamId::fromString($eventPayload['contentStreamId'])
: $this->currentContentStreamId
ContentStreamId::fromString($eventPayload['contentStreamId'])
);

$this->publishEvent('SubtreeWasTagged', $streamName->getEventStreamName(), $eventPayload);
Expand All @@ -104,9 +102,7 @@ public function theEventSubtreeWasUntaggedWasPublishedWithPayload(TableNode $pay
{
$eventPayload = $this->readPayloadTable($payloadTable);
$streamName = ContentStreamEventStreamName::fromContentStreamId(
array_key_exists('contentStreamId', $eventPayload)
? ContentStreamId::fromString($eventPayload['contentStreamId'])
: $this->currentContentStreamId
ContentStreamId::fromString($eventPayload['contentStreamId'])
);

$this->publishEvent('SubtreeWasUntagged', $streamName->getEventStreamName(), $eventPayload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function iExpectTheNodeAggregateToExist(string $serializedNodeAggregateId
$nodeAggregateId = NodeAggregateId::fromString($serializedNodeAggregateId);
$this->initializeCurrentNodeAggregate(function (ContentGraphInterface $contentGraph) use ($nodeAggregateId) {
$currentNodeAggregate = $contentGraph->findNodeAggregateById($nodeAggregateId);
Assert::assertNotNull($currentNodeAggregate, sprintf('Node aggregate "%s" was not found in the current content stream "%s".', $nodeAggregateId->value, $this->currentContentStreamId->value));
Assert::assertNotNull($currentNodeAggregate, sprintf('Node aggregate "%s" was not found in the current workspace "%s".', $nodeAggregateId->value, $this->currentWorkspaceName->value));
return $currentNodeAggregate;
});
}
Expand Down
Loading

0 comments on commit 8701a6f

Please sign in to comment.