Beispiel #1
0
 /**
  * @test
  */
 public function raisesAnExceptionIfTheEventIdIsInvalidWhenSettingTheDoEvent()
 {
     $state = new State('foo');
     try {
         $state->setDoEvent(new TransitionEvent('bar'));
     } catch (InvalidEventException $e) {
         return;
     }
     $this->fail('An expected exception has not been raised.');
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  *
  * @throws InvalidEventException
  *
  * @since Method available since Release 2.2.0
  */
 public function addTransitionEvent(TransitionEventInterface $event)
 {
     if ($event->getEventId() != EventInterface::EVENT_START) {
         throw new InvalidEventException(sprintf('The transition event for the state "%s" should be "%s", "%s" is specified.', $this->getStateId(), EventInterface::EVENT_START, $event->getEventId()));
     }
     parent::addTransitionEvent($event);
 }
 /**
  * Adds a state to the state machine.
  *
  * @param string $stateId
  */
 public function addState($stateId)
 {
     $state = new State($stateId);
     $state->setEntryEvent(new EntryEvent());
     $state->setExitEvent(new ExitEvent());
     $state->setDoEvent(new DoEvent());
     $this->stateMachine->addState($state);
 }
Beispiel #4
0
 /**
  * @test
  *
  * @since Method available since Release 2.1.0
  */
 public function isAnEndStateIfAtLeastATransitionEventIsAnEndEvent()
 {
     $event1 = \Phake::mock('Stagehand\\FSM\\Event\\TransitionEventInterface');
     \Phake::when($event1)->getEventId()->thenReturn('bar');
     \Phake::when($event1)->isEndEvent()->thenReturn(false);
     $event2 = \Phake::mock('Stagehand\\FSM\\Event\\TransitionEventInterface');
     \Phake::when($event2)->getEventId()->thenReturn('baz');
     \Phake::when($event2)->isEndEvent()->thenReturn(true);
     $state = new State('foo');
     $state->addTransitionEvent($event1);
     $state->addTransitionEvent($event2);
     $result = $state->isEndState();
     $this->assertThat($result, $this->isTrue());
     \Phake::verify($event1)->isEndEvent();
     \Phake::verify($event2)->isEndEvent();
 }