/** * 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; }
/** * @param \Khaos\FSM\State\State $s1 */ function it_can_construct_default_transition_to_add_to_state($s1) { $s1->__toString()->willReturn('S1'); $s2 = new DefaultState('S2'); $s1->addTransition(Argument::any())->willReturn(null); $this->addState($s1); $this->addTransition('t1', $s1, $s2); $expect = new DefaultTransition('t1', $s2); $s1->addTransition(Argument::that(function ($actual) use($expect) { return $actual == $expect; }))->shouldHaveBeenCalled(); }
/** * @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(); }