/**
  * @param \Khaos\FSM\State\State $from
  */
 function it_builds_default_transition_based_on_given_details($from)
 {
     $to = new DefaultState('S1');
     $guard = function () {
         return true;
     };
     $action = function () {
         return 'applied';
     };
     $expect = new DefaultTransition('t1', $to, $guard, $action);
     $this->to($to)->when('t1', $guard)->then($action);
     $this->done();
     $from->addTransition($expect)->shouldHaveBeenCalled();
 }
 /**
  * Done
  *
  * @return Definition
  * @throws Exception
  */
 public function done()
 {
     if ($this->to === null) {
         throw new Exception('Missing To State');
     }
     if ($this->label == null) {
         throw new Exception('Missing Label');
     }
     $this->from->addTransition(new DefaultTransition($this->label, $this->to, $this->guard, $this->action));
     return $this->from;
 }
Exemple #3
0
 /**
  * Visit State
  *
  * @param State $state
  *
  * @return void
  */
 public function visit(State $state)
 {
     foreach ($state->getTransitions() as $transition) {
         $this->transitions[$transition] = 'T' . ++$this->id;
     }
 }
 /**
  * Copy
  *
  * Perform deep clone
  *
  * @param State[] $visited
  *
  * @return Transition
  */
 public function copy(&$visited = [])
 {
     return new DefaultTransition($this->label, $this->to->copy($visited), $this->guard, $this->action);
 }
 /**
  * @inheritDoc
  */
 public function copy(&$visited = [])
 {
     return new self($this->argument, $this->to->copy($visited));
 }
 /**
  * @param \Khaos\FSM\State\State $to
  */
 function it_can_be_copied($to)
 {
     $visited = [];
     $to->copy($visited)->willReturn(new DefaultState('State A'));
     $this->copy()->shouldBeLike(new DefaultTransition('Transition A', new DefaultState('State A'), null, null));
 }
 /**
  * @param \Khaos\FSM\State\State $initialState
  * @param \Khaos\FSM\Transition\Transition $t1
  */
 function it_provides_the_transitions_of_the_current_state($initialState, $t1)
 {
     $initialState->getTransitions()->willReturn([$t1]);
     $this->getTransitions()->shouldReturn([$t1]);
 }
 /**
  * @inheritDoc
  */
 public function copy(&$visited = [])
 {
     return new self($this->optionDefinition, $this->to->copy($visited));
 }
 /**
  * @param \Khaos\FSM\State\State $s1
  * @param \Khaos\FSM\State\State $s2
  */
 function it_can_have_the_initial_state_changed($s1, $s2)
 {
     $s1->__toString()->willReturn('S1');
     $s2->__toString()->willReturn('S2');
     $this->addState($s1);
     $this->addState($s2);
     $this->setInitialState($s2);
     $this->getInitialState()->shouldReturn($s2);
 }
 /**
  * @inheritDoc
  */
 public function copy(&$visited = [])
 {
     return new self($this->command, $this->to->copy($visited));
 }