Exemple #1
0
 /**
  * @return ActionInterface
  */
 protected function getAction()
 {
     if (!$this->action) {
         $this->action = $this->actionAssembler->assemble($this->processDefinition->getActionsConfiguration());
     }
     return $this->action;
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 public function execute($context)
 {
     if (!$this->action) {
         $this->action = $this->assembler->assemble($this->configuration);
     }
     $this->action->execute($context);
 }
Exemple #3
0
 public function testExecutePreConditionsAreNotMet()
 {
     $context = [];
     $conditionConfiguration = ['test' => []];
     $condition = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Condition\\Configurable')->disableOriginalConstructor()->getMock();
     $condition->expects($this->any())->method('evaluate')->with($context)->will($this->returnValue(false));
     $this->processDefinition->expects($this->once())->method('getPreConditionsConfiguration')->will($this->returnValue($conditionConfiguration));
     $this->conditionFactory->expects($this->once())->method('create')->with(ConfigurableCondition::ALIAS, $conditionConfiguration)->will($this->returnValue($condition));
     $this->processDefinition->expects($this->never())->method('getActionsConfiguration');
     $this->actionAssembler->expects($this->never())->method('assemble');
     $this->process->execute($context);
 }
 /**
  * @param array $source
  * @param array $expected
  *
  * @dataProvider assembleDataProvider
  */
 public function testAssemble(array $source, array $expected)
 {
     $test = $this;
     $actionFactory = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Action\\ActionFactory')->disableOriginalConstructor()->setMethods(array('create'))->getMock();
     $actionFactory->expects($this->any())->method('create')->will($this->returnCallback(function ($type, $options, $condition) use($test) {
         if ($type == TreeExecutor::ALIAS) {
             $action = $test->getTreeExecutorMock();
         } else {
             $action = new ArrayAction(array('_type' => $type));
             $action->initialize($options);
         }
         if ($condition) {
             $action->setCondition($condition);
         }
         return $action;
     }));
     $conditionFactory = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Condition\\ConditionFactory')->disableOriginalConstructor()->setMethods(array('create'))->getMock();
     $conditionFactory->expects($this->any())->method('create')->will($this->returnCallback(function ($type, $options) {
         $condition = new ArrayCondition(array('_type' => $type));
         $condition->initialize($options);
         return $condition;
     }));
     $configurationPass = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\ConfigurationPass\\ConfigurationPassInterface')->getMockForAbstractClass();
     $configurationPass->expects($this->any())->method('passConfiguration')->with($this->isType('array'))->will($this->returnCallback(function (array $data) {
         $data['_pass'] = true;
         return $data;
     }));
     /** @var ActionFactory $actionFactory */
     /** @var ConditionFactory $conditionFactory */
     $assembler = new ActionAssembler($actionFactory, $conditionFactory);
     $assembler->addConfigurationPass($configurationPass);
     /** @var TreeExecutor $actualTree */
     $actualTree = $assembler->assemble($source);
     $this->assertInstanceOf('Oro\\Bundle\\WorkflowBundle\\Model\\Action\\TreeExecutor', $actualTree);
     $this->assertEquals($expected, $this->getActions($actualTree));
 }