/**
  * @return StateMachineInterface
  */
 public function build()
 {
     $stateMachineBuilder = new StateMachineBuilder('registration');
     $stateMachineBuilder->addState('input');
     $stateMachineBuilder->addState('confirmation');
     $stateMachineBuilder->addState('success');
     $stateMachineBuilder->setStartState('input');
     $stateMachineBuilder->addTransition('input', 'confirmation', 'confirmation');
     $stateMachineBuilder->addTransition('confirmation', 'success', 'success');
     $stateMachineBuilder->addTransition('confirmation', 'input', 'input');
     $stateMachineBuilder->setEndState('success', StateInterface::STATE_FINAL);
     return $stateMachineBuilder->getStateMachine();
 }
Esempio n. 2
0
 /**
  * @param \Stagehand\FSM\State\StateInterface $state
  * @since Method available since Release 2.0.0
  */
 protected function addState(StateInterface $state)
 {
     $state->setEntryEvent(new EntryEvent());
     $state->setExitEvent(new ExitEvent());
     $state->setDoEvent(new DoEvent());
     $this->stateMachineBuilder->getStateMachine()->addState($state);
 }
Esempio n. 3
0
 /**
  * @test
  *
  * @since Method available since Release 2.3.0
  */
 public function logsTransitions()
 {
     $stateMachine = $this->stateMachineBuilder->getStateMachine();
     $stateMachine->start();
     $stateMachine->triggerEvent('next');
     $stateMachine->triggerEvent('valid');
     $stateMachine->triggerEvent('next');
     $stateMachine->triggerEvent('next');
     $stateMachine->triggerEvent('next');
     $transitionLogs = $stateMachine->getTransitionLog();
     $expectedTransitionLogs = array(array(StateInterface::STATE_INITIAL, EventInterface::EVENT_START, 'Input'), array('Input', 'next', 'Validation'), array('Validation', 'valid', 'Confirmation'), array('Confirmation', 'next', 'Registration'), array('Registration', 'next', 'Success'), array('Success', 'next', StateInterface::STATE_FINAL));
     $this->assertThat(count($transitionLogs), $this->equalTo(count($expectedTransitionLogs)));
     for ($i = 0; $i < count($transitionLogs); ++$i) {
         $this->assertThat($transitionLogs[$i]->getFromState()->getStateId(), $this->equalTo($expectedTransitionLogs[$i][0]));
         $this->assertThat($transitionLogs[$i]->getEvent()->getEventId(), $this->equalTo($expectedTransitionLogs[$i][1]));
         $this->assertThat($transitionLogs[$i]->getToState()->getStateId(), $this->equalTo($expectedTransitionLogs[$i][2]));
         $this->assertThat($transitionLogs[$i]->getTransitionDate(), $this->isInstanceOf('DateTime'));
     }
 }
 /**
  * @test
  *
  * @since Method available since Release 2.1.0
  */
 public function setsTheStateMachineObject()
 {
     $stateMachine1 = \Phake::mock('Stagehand\\FSM\\StateMachine\\StateMachineInterface');
     $stateMachineBuilder = new StateMachineBuilder($stateMachine1);
     $stateMachine2 = $stateMachineBuilder->getStateMachine();
     $this->assertThat($stateMachine2, $this->identicalTo($stateMachine1));
 }
 /**
  * {@inheritDoc}
  */
 public function __construct($pageflowId)
 {
     parent::__construct(new Pageflow($pageflowId));
 }