getAutomation(); $registry = $this->make(Registry::class, [ 'steps' => [ 'core:root' => $this->make(RootStep::class, [ 'validate' => Expected::once(function (StepValidationArgs $args) use ($automation) { $this->assertSame($automation, $args->getAutomation()); $this->assertSame($automation->getStep('root'), $args->getStep()); $this->assertSame([], $args->getSubjects()); }), ]), ], ]); $rule = new ValidStepValidationRule($registry); (new AutomationWalker())->walk($automation, [$rule]); } public function testItCollectsAvailableSubjects(): void { $subjectA = $this->makeEmpty(Subject::class, ['getKey' => 'test:subject-a']); $subjectB = $this->makeEmpty(Subject::class, ['getKey' => 'test:subject-b']); $registry = $this->make(Registry::class, [ 'steps' => [ 'core:root' => $this->make(RootStep::class, [ 'validate' => Expected::once(function (StepValidationArgs $args) { $this->assertSame([], $args->getSubjects()); }), ]), ], ]); $registry->addTrigger( $this->makeEmpty(Trigger::class, [ 'getKey' => 'test:trigger', 'getSubjectKeys' => ['test:subject-a', 'test:subject-b'], 'validate' => Expected::once(function (StepValidationArgs $args) { $this->assertSame([], $args->getSubjects()); }), ]) ); $registry->addAction( $this->makeEmpty(Action::class, [ 'getKey' => 'test:action', 'validate' => Expected::once(function (StepValidationArgs $args) use ($subjectA, $subjectB) { $this->assertSame([$subjectA, $subjectB], $args->getSubjects()); }), ]) ); $registry->addSubject($subjectA); $registry->addSubject($subjectB); $automation = $this->make(Automation::class, [ 'getId' => 1, 'steps' => [ 'root' => new Step('root', 'root', 'core:root', [], [new NextStep('t')]), 't' => new Step('t', 'trigger', 'test:trigger', [], [new NextStep('a')]), 'a' => new Step('a', 'action', 'test:action', [], []), ], ]); $rule = new ValidStepValidationRule($registry); (new AutomationWalker())->walk($automation, [$rule]); } public function testItSkipsArgsValidationForNonExistentStep(): void { $registry = $this->make(Registry::class); $rule = new ValidStepValidationRule($registry); $automation = $this->getAutomation(); (new AutomationWalker())->walk($automation, [$rule]); } private function getAutomation(): Automation { return $this->make(Automation::class, [ 'steps' => [ 'root' => new Step('root', 'root', 'core:root', [], []), ], ]); } }