/** * @param Beanie $beanie * @param QManConfig $config * @param EventLoop $eventLoop * @param CommandSerializerInterface $commandSerializer * @param JobFailureStrategyInterface $jobFailureStrategy * @param ShutdownHandlerInterface $shutdownHandler * @param LoggerInterface $logger */ public function __construct(Beanie $beanie, QManConfig $config, EventLoop $eventLoop, CommandSerializerInterface $commandSerializer, JobFailureStrategyInterface $jobFailureStrategy, ShutdownHandlerInterface $shutdownHandler, LoggerInterface $logger) { $this->logger = $logger; $this->config = $config; $this->eventLoop = $eventLoop; $this->commandSerializer = $commandSerializer; $this->jobFailureStrategy = $jobFailureStrategy; $this->shutdownHandler = $shutdownHandler; $this->eventLoop->setJobListenerRemovedCallback([$this, 'removedJobListenerCallback']); $this->eventLoop->setJobReceivedCallback([$this, 'handleJob']); $this->beanie = $beanie; $this->config->lock(); }
public function testRegisterJobListener_triggerEventCallbackThrowsGenericException_callsCallback() { /** @var \PHPUnit_Framework_MockObject_MockObject|\Beanie\Worker $workerMock */ $workerMock = $this->getMockBuilder(BeanieWorker::class)->disableOriginalConstructor()->setMethods(['reserveOath'])->getMock(); $socket = socket_create_listen(0); /** @var \PHPUnit_Framework_MockObject_MockObject|JobOath $jobOathMock */ $jobOathMock = $this->getMockBuilder(JobOath::class)->disableOriginalConstructor()->setMethods(['getSocket', 'invoke'])->getMock(); $jobOathMock->expects($this->once())->method('getSocket')->willReturn($socket); $jobOathMock->expects($this->once())->method('invoke')->willReturn('Job'); $workerMock->expects($this->once())->method('reserveOath')->willReturn($jobOathMock); $eventLoop = new EventLoop(); $eventLoop->setJobReceivedCallback(function ($job) { $this->assertEquals('Job', $job); throw new \RuntimeException('go handle this'); })->setJobListenerRemovedCallback(function () { $this->fail('should not be called'); }); $eventLoop->registerJobListener($workerMock); $watcher = $eventLoop->getWatchers()[0]; $watcher->invoke(\Ev::READ); socket_close($socket); }