Автор: Oliver Tischlinger
Наследование: implements MetaborStd\Statemachine\StateCollectionInterface, implements MetaborStd\MergeableInterface
 /**
  * @see \MetaborStd\NamedInterfaceTest::createTestInstance()
  */
 protected function createTestInstance()
 {
     $name = $this->getOneStateNameOfTheCollection();
     $state = new State($name);
     $instance = new StateCollection();
     $instance->addState($state);
     return $instance;
 }
 /**
  *
  */
 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);
 }
Пример #4
0
 public function testAddsStatesToGraph()
 {
     $state = new State('first');
     $stateCollection = new StateCollection();
     $stateCollection->addState($state);
     $secondState = new State('second');
     $state->addTransition(new Transition($secondState));
     $graph = new Graph();
     $builder = new GraphBuilder($graph);
     $builder->addStateCollection($stateCollection);
     $this->assertTrue($graph->hasVertex('first'));
     $this->assertTrue($graph->hasVertex('second'));
 }
 public function testCopiesAllFlags()
 {
     $targetCollection = new StateCollection();
     $merger = new StateCollectionMerger($targetCollection);
     $sourceCollection = $this->createSourceCollection();
     $merger->merge($sourceCollection);
     $state = $targetCollection->getState('new');
     $this->assertArrayHasKey(self::FLAG_FOR_TEST, $state);
     $this->assertEquals(self::FLAG_FOR_TEST_VALUE, $state[self::FLAG_FOR_TEST]);
     $event = $state->getEvent('start');
     $this->assertArrayHasKey(self::FLAG_FOR_TEST, $event);
     $this->assertEquals(self::FLAG_FOR_TEST_VALUE, $event[self::FLAG_FOR_TEST]);
 }
Пример #6
0
 /**
  * @param string $name
  *
  * @return boolean
  */
 public function hasState($name)
 {
     return $this->states->hasState($name);
 }