$cachePool =
$this->
createMock(CacheItemPoolInterface::
class);
$cacheItem =
$this->
createMock(CacheItemInterface::
class);
$cacheItem->
expects($this->
once())->
method('isHit'
)->
willReturn(true
);
$cacheItem->
expects($this->
once())->
method('get'
)->
willReturn(null ===
$lastRestartTimeOffset ? null :
time() +
$lastRestartTimeOffset);
$cachePool->
expects($this->
once())->
method('getItem'
)->
willReturn($cacheItem);
$worker =
$this->
createMock(Worker::
class);
$worker->
expects($shouldStop ?
$this->
once() :
$this->
never())->
method('stop'
);
$event =
new WorkerRunningEvent($worker, false
);
$stopOnSignalListener =
new StopWorkerOnRestartSignalListener($cachePool);
$stopOnSignalListener->
onWorkerStarted();
$stopOnSignalListener->
onWorkerRunning($event);
} public static function restartTimeProvider() { yield [null, false
]; // no cached restart time, do not restart
yield [+10, true
]; // 10 seconds after starting, a restart was requested
yield [-10, false
]; // a restart was requested, but 10 seconds before we started
}