/** * Overrides the "StateMachine::execute" method * in order to support/emit the ON_EXECUTION_SUSPENDED and ON_EXECUTION_FINISHED events. * * @param StatefulSubjectInterface $subject * @param string $event_name * * @return StateInterface The state at which the execution was suspended or finished. */ public function execute(StatefulSubjectInterface $subject, $transition_event = null) { $current_state = parent::execute($subject, $transition_event); if ($this->isEventState($current_state)) { $this->fireEvent(self::ON_EXECUTION_SUSPENDED, $subject, $current_state); } else { $this->fireEvent(self::ON_EXECUTION_FINISHED, $subject, $current_state); } return $current_state; }
public function testIssue30() { $states = ['state1' => new State('state1', StateInterface::TYPE_INITIAL), 'state2' => new State('state2'), 'state2' => new State('state3', StateInterface::TYPE_FINAL)]; $transitions = ['state1' => ['_sequential' => [new Transition('state1', 'state2')]], 'state2' => ['_sequential' => [new Transition('state2', 'state3')]]]; $subject = new GenericSubject('test_machine'); $state_machine = new StateMachine('test_machine', $states, $transitions); $suspend_state = $state_machine->execute($subject); $this->assertEquals('state3', $suspend_state->getName()); }