Skip to content

Commit

Permalink
TASK: Make CommandsThatFailed::sequenceNumber internal only for tes…
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Oct 28, 2024
1 parent 0ec3a92 commit 26cb287
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Classes/CommandHandler/CommandSimulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ private function handle(RebaseableCommand $rebaseableCommand): void
} catch (\Exception $exception) {
$this->commandsThatFailedDuringRebase = $this->commandsThatFailedDuringRebase->withAppended(
new CommandThatFailedDuringRebase(
$rebaseableCommand->originalSequenceNumber,
$rebaseableCommand->originalCommand,
$exception
$exception,
$rebaseableCommand->originalSequenceNumber
)
);

Expand Down
10 changes: 5 additions & 5 deletions Classes/Feature/RebaseableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public function __construct(

public static function extractFromEventMetaData(EventMetadata $eventMetadata, SequenceNumber $sequenceNumber): self
{
if (!isset($eventMetadata->value['commandClass'])) {
throw new \RuntimeException('Command cannot be extracted from metadata, missing commandClass.', 1729847804);
}
$commandToRebaseClass = $eventMetadata->value['commandClass'] ?? null;
$commandToRebasePayload = $eventMetadata->value['commandPayload'] ?? null;

$commandToRebaseClass = $eventMetadata->value['commandClass'];
$commandToRebasePayload = $eventMetadata->value['commandPayload'];
if ($commandToRebaseClass === null || $commandToRebasePayload === null) {
throw new \RuntimeException('Command cannot be extracted from metadata, missing commandClass or commandPayload.', 1729847804);
}

if (!in_array(RebasableToOtherWorkspaceInterface::class, class_implements($commandToRebaseClass) ?: [], true)) {
throw new \RuntimeException(sprintf(
Expand Down
16 changes: 13 additions & 3 deletions Classes/Feature/WorkspaceRebase/CommandThatFailedDuringRebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@
final readonly class CommandThatFailedDuringRebase
{
/**
* @param SequenceNumber $sequenceNumber the event store sequence number of the event containing the command to be rebased
* @param CommandInterface $command the command that failed
* @param \Throwable $exception how the command failed
* @param SequenceNumber $sequenceNumber the event store sequence number of the event containing the command to be rebased
*/
public function __construct(
public SequenceNumber $sequenceNumber,
public CommandInterface $command,
public \Throwable $exception
public \Throwable $exception,
private SequenceNumber $sequenceNumber,
) {
}

/**
* The event store sequence number of the event containing the command to be rebased
*
* @internal exposed for testing
*/
public function getSequenceNumber(): SequenceNumber
{
return $this->sequenceNumber;
}
}

0 comments on commit 26cb287

Please sign in to comment.