public function testItReturnsDefaultOptionsWhenSomeRequired() { $resolver = new OptionsResolver(); $resolver->setDefaults(array('p1' => 'foo', 'p2' => 'bar')); $resolver->setRequired(array('p3')); $transition = new Transition('transition', array('s1'), 's2', null, $resolver); $this->assertSame(array('p1' => 'foo', 'p2' => 'bar'), $transition->getProperties()); $this->assertTrue($transition->has('p1')); $this->assertFalse($transition->has('p3')); $this->assertSame('bar', $transition->get('p2')); }
/** * Constructor. * * @param string $name The name of transition * @param \Kreta\Component\Workflow\Model\Interfaces\StatusInterface[] $initialStates Array that contains * the initial states * @param \Kreta\Component\Workflow\Model\Interfaces\StatusInterface $state The status */ public function __construct($name, array $initialStates = [], StatusInterface $state = null) { parent::__construct($name, $initialStates, $state); if ($state instanceof StatusInterface) { $this->workflow = $state->getWorkflow(); } }
/** * {@inheritdoc} */ public function addTransition($transition, $initialState = null, $finalState = null) { if ((null === $initialState || null === $finalState) && !$transition instanceof TransitionInterface) { throw new \InvalidArgumentException('You must provide a TransitionInterface instance or the $transition, ' . '$initialState and $finalState parameters'); } // If transition isn't a TransitionInterface instance, we create one from the states date if (!$transition instanceof TransitionInterface) { try { $transition = $this->getTransition($transition); } catch (Exception\TransitionException $e) { $transition = new Transition($transition, $initialState, $finalState); } } $this->transitions[$transition->getName()] = $transition; // We add missings states to the State Machine try { $this->getState($transition->getState()); } catch (Exception\StateException $e) { $this->addState($transition->getState()); } foreach ($transition->getInitialStates() as $state) { try { $this->getState($state); } catch (Exception\StateException $e) { $this->addState($state); } $state = $this->getState($state); if ($state instanceof State) { $state->addTransition($transition); } } }