setExitCallable() публичный метод

set the exit callable, the callable to be called when exiting this state
public setExitCallable ( callable $callable )
$callable callable
 /**
  * @test
  */
 public function shouldFailEntryAndExitWithNonCallable()
 {
     $state = new State('a');
     $context = new Context(new Identifier('123', 'foo-machine'));
     $event = 'foo';
     $callable = "Foo::BarEntry";
     $state->setEntryCallable($callable);
     $callable = "Foo::BarExit";
     $state->setExitCallable($callable);
     try {
         $state->entryAction($context);
         $this->fail('should not come here');
     } catch (Exception $e) {
         $this->assertEquals(Exception::CALLABLE_FAILURE, $e->getCode());
     }
     try {
         $state->exitAction($context);
         $this->fail('should not come here');
     } catch (Exception $e) {
         $this->assertEquals(Exception::CALLABLE_FAILURE, $e->getCode());
     }
 }
Пример #2
0
 /**
  * @test
  */
 public function shouldBeAbleToSetCallable()
 {
     $context = new Context(new Identifier('123', 'foo-machine'));
     $event = 'foo';
     //increase the id every time the callable is called
     $callable = function ($entity) {
         $entity->setEntityId($entity->getEntityId() + 1);
     };
     //scenario 1: use constructor
     $state = new State('a', State::TYPE_NORMAL, null, null, $callable, $callable);
     $this->assertEquals('123', $context->getEntityId());
     $state->entryAction($context);
     $this->assertEquals('124', $context->getEntityId());
     $state->exitAction($context);
     $this->assertEquals('125', $context->getEntityId());
     //scenario 2: use setters
     $state = new State('b', State::TYPE_NORMAL);
     $state->setEntryCallable($callable);
     $state->setExitCallable($callable);
     $this->assertEquals('125', $context->getEntityId());
     $state->entryAction($context);
     $this->assertEquals('126', $context->getEntityId());
     $state->exitAction($context);
     $this->assertEquals('127', $context->getEntityId());
 }