Skip to content
This repository has been archived by the owner on Nov 30, 2017. It is now read-only.

Commit

Permalink
Only add steps that are active
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Jul 9, 2016
1 parent aa055fc commit f249a8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Process/Builder/ProcessBuilder.php
Expand Up @@ -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);
}
Expand Down
26 changes: 26 additions & 0 deletions spec/Process/Builder/ProcessBuilderSpec.php
Expand Up @@ -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
{
Expand All @@ -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);
}
}

0 comments on commit f249a8f

Please sign in to comment.