示例#1
0
 /**
  * Execute event in set process for set payload
  * If final state has timeout event, store it for further execution
  * Return run history
  *
  * @param ProcessInterface $process
  * @param PayloadInterface $payload
  * @param string           $event
  *
  * @return array
  */
 private function resolveEvent(ProcessInterface $process, PayloadInterface $payload, $event)
 {
     $result = $process->triggerEvent($event, $payload);
     if ($payload->hasChanged() && $process->hasTimeout($payload)) {
         $this->timeoutHandler->store($process->getTimeout($payload, new \DateTime()));
     }
     $this->payloadHandler->store($payload);
     return $result;
 }
示例#2
0
 public function testResolveTimeoutsWithPayloadInCorrectState()
 {
     $timeout = $this->getMockBuilder('\\StateMachine\\PayloadTimeout')->disableOriginalConstructor()->getMock();
     $timeout->expects($this->any())->method('getState')->willReturn('timeout');
     $this->timeoutHandler->expects($this->any())->method('getExpired')->willReturn([$timeout]);
     $this->payload->expects($this->any())->method('getState')->willReturn('timeout');
     $this->payloadHandler->expects($this->any())->method('restore')->willReturn($this->payload);
     $this->adapter->expects($this->any())->method('getProcess')->willReturn($this->process);
     $this->process->expects($this->once())->method('triggerEvent');
     $this->timeoutHandler->expects($this->once())->method('remove');
     $machine = new StateMachine($this->adapter, $this->payloadHandler, $this->timeoutHandler, $this->lockHandler);
     $machine->resolveTimeouts();
 }