public function testAdditionalExceptionPropertiesAreAccessibleViaGeters()
 {
     $input = FlyweightInput::named('BAR');
     $object = new StatefulObject();
     $object->setCurrentState(FlyweightState::named('FOO'));
     $context = new Context();
     $nextState = FlyweightState::named('FOOBAR');
     $previous = new \Exception();
     $exception = new StateTransitionFailed($input, $object, $context, $nextState, $previous);
     $this->assertSame($input, $exception->getInput());
     $this->assertSame($object, $exception->getObject());
     $this->assertSame($context, $exception->getContext());
     $this->assertSame($nextState, $exception->getNextState());
     $this->assertSame($previous, $exception->getPrevious());
 }
Ejemplo n.º 2
0
 public function testCanOverrideDefaultStateChangerListener()
 {
     $object = new StatefulObject();
     $object->setCurrentState(FlyweightState::named('WHITES_TURN'));
     $stateChanger = new class extends InvokableListener
     {
         public function __invoke(EventInterface $event, Stateful $object, Context $context, Input $input, State $nextState)
         {
             $object->setCurrentState(FlyweightState::named('it worked!'));
         }
     };
     $statemachine = new Statemachine(new ChessMatchTransitionTable(), null, $stateChanger);
     $statemachine->trigger(FlyweightInput::named('WHITE_MOVES'), $object);
     $this->assertSame(FlyweightState::named('it worked!'), $object->getCurrentState());
 }