diff --git a/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/NoDuplicateEdgesRule.php b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/NoDuplicateEdgesRule.php new file mode 100644 index 0000000000..dc63195a7b --- /dev/null +++ b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/NoDuplicateEdgesRule.php @@ -0,0 +1,26 @@ +getStep()->getNextSteps() as $nextStep) { + if (isset($visitedNextStepIdsMap[$nextStep->getId()])) { + throw Exceptions::workflowStructureNotValid(__('Duplicate next step definition found', 'mailpoet')); + } + $visitedNextStepIdsMap[$nextStep->getId()] = true; + } + } + + public function complete(Workflow $workflow): void { + } +} diff --git a/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/NoDuplicateEdgesTest.php b/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/NoDuplicateEdgesTest.php new file mode 100644 index 0000000000..40fc44c657 --- /dev/null +++ b/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/NoDuplicateEdgesTest.php @@ -0,0 +1,33 @@ +createWorkflow([ + 'root' => ['a', 'a'], + 'a' => [], + ]); + + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Invalid workflow structure: Duplicate next step definition found'); + (new WorkflowWalker())->walk($workflow, [new NoDuplicateEdgesRule()]); + } + + public function testItPassesWithSingleEdges(): void { + $workflow = $this->createWorkflow([ + 'root' => ['a'], + 'a' => ['b'], + 'b' => ['c'], + 'c' => [], + ]); + + (new WorkflowWalker())->walk($workflow, [new NoDuplicateEdgesRule()]); + // no exception thrown + } +}