Author: Oliver Tischlinger
 /**
  *
  */
 public function testFiltersStatesThatHaveNoOutgoingTransitions()
 {
     $eventName = 'event';
     $stateCollection = new StateCollection();
     $helper = new SetupHelper($stateCollection);
     $helper->findOrCreateTransition('foo', 'bar', $eventName);
     $filter = new FilterStateByFinalState($stateCollection->getStates());
     $filteredStates = iterator_to_array($filter);
     $this->assertContains($stateCollection->getState('bar'), $filteredStates);
     $this->assertNotContains($stateCollection->getState('foo'), $filteredStates);
 }
 /**
  *
  */
 public function testFiltersStatesThatHaveTransitionsWithoutAnEvent()
 {
     $eventName = 'event';
     $stateCollection = new StateCollection();
     $helper = new SetupHelper($stateCollection);
     $helper->findOrCreateTransition('foo', 'bar', $eventName);
     $helper->findOrCreateTransition('bar', 'baz', null, new Tautology('condition'));
     $filter = new FilterStateByTransition($stateCollection->getStates());
     $filteredStates = iterator_to_array($filter);
     $this->assertNotContains($stateCollection->getState('foo'), $filteredStates);
     $this->assertContains($stateCollection->getState('bar'), $filteredStates);
     $this->assertNotContains($stateCollection->getState('baz'), $filteredStates);
 }
 /**
  *
  */
 public function testTriggerEventIfStatusIsChangedAndNewStateHasRegisteredEvent()
 {
     $process = new Process('process_name', new State('initinal'));
     $collection = new StateCollection();
     $helper = new SetupHelper($collection);
     $helper->findOrCreateTransition('initinal', 'second', 'go');
     $helper->findOrCreateTransition('second', 'error', 'error');
     $eventName = 'eventName';
     $helper->findOrCreateTransition('second', 'final', $eventName);
     $process->merge($collection);
     $subject = new \stdClass();
     $statemachine = new Statemachine($subject, $process);
     $statemachine->attach(new OnEnterObserver($eventName));
     $statemachine->triggerEvent('go');
     $this->assertEquals($process->getState('final'), $statemachine->getCurrentState());
 }