示例#1
0
 public function testGuard()
 {
     $subject = new GenericSubject('test_machine', 'state1');
     $guard = new VariableGuard(['expression' => 'event === "erp.derped"']);
     $subject->getExecutionContext()->setParameter('event', 'erp.derped');
     $this->assertTrue($guard->accept($subject));
     $this->assertEquals(PHP_EOL . 'if event === "erp.derped"', $guard->__toString());
 }
示例#2
0
 public function testExecuteSimpleDecisionTrue()
 {
     $subject = new GenericSubject('test_machine', 'new');
     $states = ['new' => new State('new', StateInterface::TYPE_INITIAL), 'transcoding' => new State('transcoding'), 'ready' => new State('ready', StateInterface::TYPE_FINAL)];
     $transitions = ['new' => ['promote' => [new Transition('new', 'transcoding', new ExpressionGuard(['expression' => 'params.transcoding_required'])), new Transition('new', 'ready', new ExpressionGuard(['expression' => 'not params.transcoding_required']))]], 'transcoding' => ['promote' => [new Transition('transcoding', 'ready')]]];
     $state_machine = new StateMachine('test_machine', $states, $transitions);
     $subject->getExecutionContext()->setParameter('transcoding_required', true);
     $target_state = $state_machine->execute($subject, 'promote');
     $this->assertEquals('transcoding', $target_state->getName());
 }
示例#3
0
 public function testOnExit()
 {
     $state_vars = ['foo' => 42];
     $state = new VariableState('state1', StateInterface::TYPE_INITIAL, ['variables' => $state_vars, 'remove_variables' => array_keys($state_vars)]);
     $subject = new GenericSubject('test_machine', 'state1');
     $this->assertEquals([], $subject->getExecutionContext()->getParameters()->toArray());
     $state->onEntry($subject);
     $this->assertEquals($state_vars, $subject->getExecutionContext()->getParameters()->toArray());
     $state->onExit($subject);
     $this->assertEquals([], $subject->getExecutionContext()->getParameters()->toArray());
 }
 public function testErrorFlow()
 {
     $builder = new XmlStateMachineBuilder(['state_machine_definition' => __DIR__ . '/Fixture/state_machine.xml', 'name' => 'video_transcoding']);
     $state_machine = $builder->build();
     $subject = new GenericSubject('video_transcoding', 'new');
     $subject->getExecutionContext()->setParameter('transcoding_required', true);
     $next_state = $state_machine->execute($subject, 'promote');
     $this->assertEquals('error', $next_state->getName());
     $subject->getExecutionContext()->setParameter('retry_limit_reached', true);
     $next_state = $state_machine->execute($subject, 'promote');
     $this->assertEquals('rejected', $next_state->getName());
 }