/** * Resolve single timeout * *@param ProcessInterface $process * @param PayloadTimeout $timeout * @param array $result */ private function resolveTimeout(ProcessInterface $process, PayloadTimeout $timeout, &$result) { if ($this->lockHandler->isLocked($timeout->getIdentifier())) { return; } $this->lockHandler->lock($timeout->getIdentifier()); $payload = $this->payloadHandler->restore($timeout->getIdentifier()); if ($payload->getState() === $timeout->getState()) { $result[$timeout->getIdentifier()] = $this->resolveEvent($process, $payload, $timeout->getEvent()); } $this->timeoutHandler->remove($timeout); $this->lockHandler->release($timeout->getIdentifier()); }
public function testResolveTimeoutsAndLockWithPayloadInCorrectStateButLocked() { $timeout = $this->getMockBuilder('\\StateMachine\\PayloadTimeout')->disableOriginalConstructor()->getMock(); $timeout->expects($this->any())->method('getState')->willReturn('timeout'); $timeout->expects($this->any())->method('getIdentifier')->willReturn('identifier'); $this->timeoutHandler->expects($this->any())->method('getExpired')->willReturn([$timeout]); $this->lockHandler->expects($this->any())->method('isLocked')->willReturn(true); $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->lockHandler->expects($this->never())->method('lock')->with('identifier'); $this->lockHandler->expects($this->never())->method('release')->with('identifier'); $machine = new StateMachine($this->adapter, $this->payloadHandler, $this->timeoutHandler, $this->lockHandler); $machine->resolveTimeouts(); }