diff --git a/Process/Builder/ProcessBuilder.php b/Process/Builder/ProcessBuilder.php index 423f097..c283130 100644 --- a/Process/Builder/ProcessBuilder.php +++ b/Process/Builder/ProcessBuilder.php @@ -79,6 +79,10 @@ public function add($name, $step) throw new \InvalidArgumentException('Step added via builder must implement "Sylius\Bundle\FlowBundle\Process\Step\StepInterface"'); } + if (!$step->isActive()) { + return $this; + } + if ($step instanceof ContainerAwareInterface) { $step->setContainer($this->container); } diff --git a/spec/Process/Builder/ProcessBuilderSpec.php b/spec/Process/Builder/ProcessBuilderSpec.php index 38f3edb..8ec2e5d 100644 --- a/spec/Process/Builder/ProcessBuilderSpec.php +++ b/spec/Process/Builder/ProcessBuilderSpec.php @@ -14,6 +14,9 @@ use PhpSpec\ObjectBehavior; use Sylius\Bundle\FlowBundle\Process\Builder\ProcessBuilderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Sylius\Bundle\FlowBundle\Process\Step\StepInterface; +use Sylius\Bundle\FlowBundle\Process\Scenario\ProcessScenarioInterface; +use Prophecy\Argument; class ProcessBuilderSpec extends ObjectBehavior { @@ -31,4 +34,27 @@ function it_is_process_builder() { $this->shouldImplement(ProcessBuilderInterface::class); } + + function it_should_not_add_inactive_steps( + StepInterface $step, + ProcessScenarioInterface $scenario + ) { + $this->build($scenario); + $step->isActive()->willReturn(false); + $step->setName(Argument::any())->shouldNotBeCalled(); + + $this->add('foobar', $step); + } + + function it_should_add_active_steps( + StepInterface $step, + ProcessScenarioInterface $scenario + ) { + $step->getName()->willReturn(null); + $this->build($scenario); + $step->isActive()->willReturn(true); + $step->setName('foobar')->shouldBeCalled(); + + $this->add('foobar', $step); + } }