Example #1
0
    public function testGetStateMachine()
    {
        $sm = $this->object->getStateMachine($this->getObjectMock());

        $this->assertInstanceOf('Finite\StateMachine\StateMachine', $sm);
        $this->assertSame('s1', $sm->getCurrentState()->getName());
    }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function apply(CartInterface $cart, $transition, $andFlush = false)
 {
     $finiteStateMachine = $this->finiteContext->getStateMachine($cart);
     if ($finiteStateMachine->can($transition)) {
         $finiteStateMachine->apply($transition);
         if ($andFlush) {
             $this->cartManager->updateCart($cart);
         }
         return true;
     }
     throw new TransitionException($transition, $cart->getState());
 }
Example #3
0
 public function testItRetrievesGoodStateMachine()
 {
     $object = $this->getMock('Finite\\StatefulInterface');
     $factory = $this->getMock('Finite\\Factory\\FactoryInterface');
     $sm = $this->getMock('Finite\\StateMachine\\StateMachineInterface');
     $factory->expects($this->once())->method('get')->with($object, 'foo')->will($this->returnValue($sm));
     $context = new Context($factory);
     $this->assertSame($sm, $context->getStateMachine($object, 'foo'));
 }
Example #4
0
 /**
  * @param object $object
  * @param string $transition
  * @param string $graph
  *
  * @return bool|mixed
  */
 public function canFiniteTransition($object, $transition, $graph = 'default')
 {
     return $this->context->getStateMachine($object, $graph)->can($transition);
 }
 /**
  * @param StatefulInterface $object
  * @param $transition
  *
  * @return bool|mixed
  */
 public function canFiniteTransition(StatefulInterface $object, $transition)
 {
     return $this->context->getStateMachine($object)->can($transition);
 }