diff --git a/Command/RetryCommand.php b/Command/RetryCommand.php index 27e8ff9..9019f74 100644 --- a/Command/RetryCommand.php +++ b/Command/RetryCommand.php @@ -33,9 +33,6 @@ class RetryCommand extends Command /** * RetryCommand constructor. - * - * @param JobQueue $queue - * @param MongoDriverInterface $mongoDriver */ public function __construct(JobQueue $queue, FailedJobProviderInterface $failer) { @@ -58,10 +55,7 @@ protected function configure() /** * Execute command * - * @param InputInterface $input - * @param OutputInterface $output - * - * @return int|null|void + * @return int|void|null */ public function execute(InputInterface $input, OutputInterface $output) { @@ -82,14 +76,12 @@ public function execute(InputInterface $input, OutputInterface $output) } $io->success(sprintf("[%d] job(s) has been released.\n", $jobsCount)); + + return 0; } /** * Retry job - * - * @param Job $job - * - * @return bool */ protected function retryJob(Job $job): bool { diff --git a/Command/RunJobCommand.php b/Command/RunJobCommand.php index d2dac16..3755a09 100644 --- a/Command/RunJobCommand.php +++ b/Command/RunJobCommand.php @@ -24,8 +24,6 @@ class RunJobCommand extends Command /** * RunJobCommand constructor. - * - * @param LoggerInterface $logger * @param Worker $worker */ public function __construct(Worker $worker) @@ -55,10 +53,7 @@ protected function configure() /** * Execute command * - * @param InputInterface $input - * @param OutputInterface $output - * - * @return int|null|void + * @return int|void|null */ public function execute(InputInterface $input, OutputInterface $output) { @@ -73,5 +68,7 @@ public function execute(InputInterface $input, OutputInterface $output) $jobId = $input->getArgument('id'); $this->worker->runJobById($connection, $jobId, $options); + + return 0; } } diff --git a/Command/WorkCommand.php b/Command/WorkCommand.php index 3ec372c..adb9a92 100644 --- a/Command/WorkCommand.php +++ b/Command/WorkCommand.php @@ -27,8 +27,6 @@ class WorkCommand extends Command /** * WorkCommand constructor. - * - * @param Worker $worker */ public function __construct(Worker $worker) { @@ -56,10 +54,7 @@ protected function configure() /** * Execute command * - * @param InputInterface $input - * @param OutputInterface $output - * - * @return int|null|void + * @return int|void|null */ public function execute(InputInterface $input, OutputInterface $output) { @@ -78,5 +73,7 @@ public function execute(InputInterface $input, OutputInterface $output) $io->success(sprintf('Worker daemon has started.')); $this->worker->daemon($connection, $queue, $workerOptions); + + return 0; } } diff --git a/DependencyInjection/QueueExtension.php b/DependencyInjection/QueueExtension.php index c3099f1..4dfb15e 100644 --- a/DependencyInjection/QueueExtension.php +++ b/DependencyInjection/QueueExtension.php @@ -21,7 +21,6 @@ use SfCod\QueueBundle\Service\QueueManager; use SfCod\QueueBundle\Worker\Worker; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -265,6 +264,7 @@ private function createJobProcess(array $config, ContainerBuilder $container) $jobProcess->setArguments([ 'console', sprintf('%s/bin', $container->getParameter('kernel.project_dir')), + $container->getParameter('kernel.environment'), ]); $container->setDefinition(JobProcess::class, $jobProcess); diff --git a/Event/JobExceptionOccurredEvent.php b/Event/JobExceptionOccurredEvent.php index 3b86781..3b1f4e6 100644 --- a/Event/JobExceptionOccurredEvent.php +++ b/Event/JobExceptionOccurredEvent.php @@ -4,7 +4,7 @@ use Exception; use SfCod\QueueBundle\Job\JobContractInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class JobExceptionOccurredEvent diff --git a/Event/JobFailedEvent.php b/Event/JobFailedEvent.php index 5b0a236..d71fa86 100644 --- a/Event/JobFailedEvent.php +++ b/Event/JobFailedEvent.php @@ -4,7 +4,7 @@ use Exception; use SfCod\QueueBundle\Job\JobContractInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class JobFailedEvent @@ -43,7 +43,6 @@ class JobFailedEvent extends Event * @param string $connectionName * @param JobContractInterface $job * @param Exception $exception - * @param array $config */ public function __construct(string $connectionName, JobContractInterface $job, Exception $exception) { diff --git a/Event/JobProcessedEvent.php b/Event/JobProcessedEvent.php index 519de2c..caa52d0 100644 --- a/Event/JobProcessedEvent.php +++ b/Event/JobProcessedEvent.php @@ -3,7 +3,7 @@ namespace SfCod\QueueBundle\Event; use SfCod\QueueBundle\Job\JobContractInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class JobProcessedEvent @@ -34,7 +34,6 @@ class JobProcessedEvent extends Event * * @param string $connectionName * @param JobContractInterface $job - * @param array $config */ public function __construct(string $connectionName, JobContractInterface $job) { diff --git a/Event/JobProcessingEvent.php b/Event/JobProcessingEvent.php index 08ce3c5..8b38345 100644 --- a/Event/JobProcessingEvent.php +++ b/Event/JobProcessingEvent.php @@ -3,7 +3,7 @@ namespace SfCod\QueueBundle\Event; use SfCod\QueueBundle\Job\JobContractInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class JobProcessingEvent @@ -34,7 +34,6 @@ class JobProcessingEvent extends Event * * @param string $connectionName * @param JobContractInterface $job - * @param array $config */ public function __construct(string $connectionName, JobContractInterface $job) { diff --git a/Event/WorkerStoppingEvent.php b/Event/WorkerStoppingEvent.php index 35ceea3..0cd274a 100644 --- a/Event/WorkerStoppingEvent.php +++ b/Event/WorkerStoppingEvent.php @@ -2,7 +2,7 @@ namespace SfCod\QueueBundle\Event; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class WorkerStoppingEvent diff --git a/Service/JobProcess.php b/Service/JobProcess.php index 132e9e9..cfff4b8 100644 --- a/Service/JobProcess.php +++ b/Service/JobProcess.php @@ -35,22 +35,30 @@ class JobProcess */ public $binaryArgs; + /** + * @var string + */ + public $environment; + /** * JobProcess constructor. * * @param string $scriptName * @param string $binPath + * @param string $environment * @param string $binary * @param string $binaryArgs */ public function __construct( string $scriptName, string $binPath, + string $environment = 'prod', string $binary = 'php', string $binaryArgs = '') { $this->scriptName = $scriptName; $this->binPath = $binPath; + $this->environment = $environment; $this->binary = $binary; $this->binaryArgs = $binaryArgs; } @@ -65,38 +73,22 @@ public function __construct( */ public function getProcess(JobContractInterface $job, Options $options): Process { - $cmd = '%s %s job-queue:run-job %s --connection=%s --queue=%s --env=%s --delay=%s --memory=%s --timeout=%s --sleep=%s --maxTries=%s'; - $cmd = $this->getBackgroundCommand($cmd); - $cmd = sprintf( - $cmd, + return new Process(array_filter([ + defined('PHP_WINDOWS_VERSION_BUILD') ? 'start /B ' : null, $this->getPhpBinary(), $this->scriptName, - (string)$job->getJobId(), - $job->getConnectionName(), - $job->getQueue(), - getenv('APP_ENV'), - $options->delay, - $options->memory, - $options->timeout, - $options->sleep, - $options->maxTries - ); - - return new Process($cmd, $this->binPath); - } - - /** - * @param $cmd - * - * @return string - */ - protected function getBackgroundCommand(string $cmd): string - { - if (defined('PHP_WINDOWS_VERSION_BUILD')) { - return 'start /B ' . $cmd . ' > NUL'; - } else { - return $cmd . ' > /dev/null 2>&1 &'; - } + 'job-queue:run-job', + $job->getJobId(), + '--connection=' . $job->getConnectionName(), + '--queue=' . $job->getQueue(), + '--env=' . $this->environment, + '--delay=' . $options->delay, + '--memory=' . $options->memory, + '--timeout=' . $options->timeout, + '--sleep=' . $options->sleep, + '--maxTries=' . $options->maxTries, + defined('PHP_WINDOWS_VERSION_BUILD') ? ' > NUL' : ' > /dev/null 2>&1 &', + ]), $this->binPath); } /** @@ -116,6 +108,6 @@ protected function getPhpBinary(): string $args = implode(' ', $args); } - return trim($path . ' ' . $args); + return trim(trim($path . ' ' . $args), '\''); } } diff --git a/Tests/Connector/MongoConnectorTest.php b/Tests/Connector/MongoConnectorTest.php index 0d1206a..a90dcff 100644 --- a/Tests/Connector/MongoConnectorTest.php +++ b/Tests/Connector/MongoConnectorTest.php @@ -36,6 +36,6 @@ public function testConnect() $queue = $connector->connect($config); - $this->assertInstanceOf(MongoQueue::class, $queue); + self::assertInstanceOf(MongoQueue::class, $queue); } } diff --git a/Tests/Data/LoadTrait.php b/Tests/Data/LoadTrait.php index 95e7466..dd87d38 100644 --- a/Tests/Data/LoadTrait.php +++ b/Tests/Data/LoadTrait.php @@ -10,6 +10,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\Dotenv\Exception\PathException; +use Symfony\Component\HttpKernel\HttpKernel; /** * Trait LoadTrait @@ -30,16 +31,10 @@ trait LoadTrait */ protected function configure() { - $dotenv = new Dotenv(); - try { - $dotenv->load(__DIR__ . '/../../.env'); - } catch (PathException $e) { - // Nothing - } - $extension = new QueueExtension(); $container = new ContainerBuilder(); - $container->setParameter('kernel.project_dir', getenv('KERNEL_PROJECT_DIR')); + $container->setParameter('kernel.project_dir', ''); + $container->setParameter('kernel.environment', 'prod'); $container->setParameter('kernel.root_dir', realpath(__DIR__ . '/../../../../SfCod/')); $container->set(LoggerInterface::class, new Logger('test')); diff --git a/Tests/Entity/JobTest.php b/Tests/Entity/JobTest.php index 15692a1..06a0d31 100644 --- a/Tests/Entity/JobTest.php +++ b/Tests/Entity/JobTest.php @@ -34,11 +34,11 @@ public function testJob() $job->setReservedAt($reservedAt); $job->setPayload($payload); - $this->assertEquals($id, $job->getId()); - $this->assertEquals($attempts, $job->getAttempts()); - $this->assertEquals($queue, $job->getQueue()); - $this->assertEquals($reserved, $job->isReserved()); - $this->assertEquals($reservedAt, $job->getReservedAt()); - $this->assertEquals($payload, $job->getPayload()); + self::assertEquals($id, $job->getId()); + self::assertEquals($attempts, $job->getAttempts()); + self::assertEquals($queue, $job->getQueue()); + self::assertEquals($reserved, $job->isReserved()); + self::assertEquals($reservedAt, $job->getReservedAt()); + self::assertEquals($payload, $job->getPayload()); } } diff --git a/Tests/Event/JobExceptionOccurredEventTest.php b/Tests/Event/JobExceptionOccurredEventTest.php index 4b7dad1..7b83706 100644 --- a/Tests/Event/JobExceptionOccurredEventTest.php +++ b/Tests/Event/JobExceptionOccurredEventTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; use SfCod\QueueBundle\Event\JobExceptionOccurredEvent; use SfCod\QueueBundle\Job\JobContractInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class JobExceptionOccurredEventTest @@ -29,10 +29,10 @@ public function testEvent() $event = new JobExceptionOccurredEvent($connectionName, $job, $exception); - $this->assertInstanceOf(Event::class, $event); - $this->assertEquals($connectionName, $event->getConnectionName()); - $this->assertEquals($job, $event->getJob()); - $this->assertEquals($exception, $event->getException()); - $this->assertEquals($exception->getMessage(), $event->getException()->getMessage()); + self::assertInstanceOf(Event::class, $event); + self::assertEquals($connectionName, $event->getConnectionName()); + self::assertEquals($job, $event->getJob()); + self::assertEquals($exception, $event->getException()); + self::assertEquals($exception->getMessage(), $event->getException()->getMessage()); } } diff --git a/Tests/Event/JobFailedEventTest.php b/Tests/Event/JobFailedEventTest.php index f90d8c9..7a90bb1 100644 --- a/Tests/Event/JobFailedEventTest.php +++ b/Tests/Event/JobFailedEventTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; use SfCod\QueueBundle\Event\JobFailedEvent; use SfCod\QueueBundle\Job\JobContractInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class JobFailedEventTest @@ -29,10 +29,10 @@ public function testEvent() $event = new JobFailedEvent($connectionName, $job, $exception); - $this->assertInstanceOf(Event::class, $event); - $this->assertEquals($connectionName, $event->getConnectionName()); - $this->assertEquals($job, $event->getJob()); - $this->assertEquals($exception, $event->getException()); - $this->assertEquals($exception->getMessage(), $event->getException()->getMessage()); + self::assertInstanceOf(Event::class, $event); + self::assertEquals($connectionName, $event->getConnectionName()); + self::assertEquals($job, $event->getJob()); + self::assertEquals($exception, $event->getException()); + self::assertEquals($exception->getMessage(), $event->getException()->getMessage()); } } diff --git a/Tests/Event/JobProcessedEventTest.php b/Tests/Event/JobProcessedEventTest.php index 8ad67b0..328240c 100644 --- a/Tests/Event/JobProcessedEventTest.php +++ b/Tests/Event/JobProcessedEventTest.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase; use SfCod\QueueBundle\Event\JobProcessedEvent; use SfCod\QueueBundle\Job\JobContractInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class JobProcessedEventTest @@ -26,8 +26,8 @@ public function testEvent() $event = new JobProcessedEvent($connectionName, $job); - $this->assertInstanceOf(Event::class, $event); - $this->assertEquals($connectionName, $event->getConnectionName()); - $this->assertEquals($job, $event->getJob()); + self::assertInstanceOf(Event::class, $event); + self::assertEquals($connectionName, $event->getConnectionName()); + self::assertEquals($job, $event->getJob()); } } diff --git a/Tests/Event/JobProcessingEventTest.php b/Tests/Event/JobProcessingEventTest.php index 2f86179..27f476c 100644 --- a/Tests/Event/JobProcessingEventTest.php +++ b/Tests/Event/JobProcessingEventTest.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase; use SfCod\QueueBundle\Event\JobProcessingEvent; use SfCod\QueueBundle\Job\JobContractInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class JobProcessingEventTest @@ -26,8 +26,8 @@ public function testEvent() $event = new JobProcessingEvent($connectionName, $job); - $this->assertInstanceOf(Event::class, $event); - $this->assertEquals($connectionName, $event->getConnectionName()); - $this->assertEquals($job, $event->getJob()); + self::assertInstanceOf(Event::class, $event); + self::assertEquals($connectionName, $event->getConnectionName()); + self::assertEquals($job, $event->getJob()); } } diff --git a/Tests/Event/WorkerStoppingEventTest.php b/Tests/Event/WorkerStoppingEventTest.php index a615358..b8b354c 100644 --- a/Tests/Event/WorkerStoppingEventTest.php +++ b/Tests/Event/WorkerStoppingEventTest.php @@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase; use SfCod\QueueBundle\Event\WorkerStoppingEvent; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class WorkerStoppingEventTest @@ -22,6 +22,6 @@ public function testEvent() { $event = new WorkerStoppingEvent(); - $this->assertInstanceOf(Event::class, $event); + self::assertInstanceOf(Event::class, $event); } } diff --git a/Tests/Exception/FatalThrowableExceptionTest.php b/Tests/Exception/FatalThrowableExceptionTest.php index 91f9705..f929170 100644 --- a/Tests/Exception/FatalThrowableExceptionTest.php +++ b/Tests/Exception/FatalThrowableExceptionTest.php @@ -25,8 +25,8 @@ public function testException() $line = __LINE__ + 1; // Exception line $exception = new FatalThrowableException(new Exception($message)); - $this->assertEquals($message, $exception->getMessage()); - $this->assertEquals(__FILE__, $exception->getFile()); - $this->assertEquals($line, $exception->getLine()); + self::assertEquals($message, $exception->getMessage()); + self::assertEquals(__FILE__, $exception->getFile()); + self::assertEquals($line, $exception->getLine()); } } diff --git a/Tests/Failer/MongoFailedJobProviderTest.php b/Tests/Failer/MongoFailedJobProviderTest.php index d5cec1e..fb11ba6 100644 --- a/Tests/Failer/MongoFailedJobProviderTest.php +++ b/Tests/Failer/MongoFailedJobProviderTest.php @@ -38,7 +38,7 @@ public function testLog() 'exception' => $exception->getMessage(), ]); - $this->assertNotNull($record, 'Log missed in mongodb.'); + self::assertNotNull($record, 'Log missed in mongodb.'); } /** @@ -55,9 +55,9 @@ public function testAll() $provider->log($connection, $queue, $payload, $exception); } - $count = $database->selectCollection($collection)->count(); + $count = $database->selectCollection($collection)->countDocuments(); - $this->assertEquals(10, $count); + self::assertEquals(10, $count); } /** @@ -79,8 +79,8 @@ public function testFind() 'exception' => $exception->getMessage(), ]); - $this->assertNotNull($record); - $this->assertInstanceOf(Job::class, $provider->find($record->_id)); + self::assertNotNull($record); + self::assertInstanceOf(Job::class, $provider->find($record->_id)); } /** @@ -106,7 +106,7 @@ public function testForget() $record = $database->selectCollection($collection)->findOne(['_id' => $record->_id]); - $this->assertNull($record); + self::assertNull($record); } /** @@ -123,14 +123,14 @@ public function testFlush() $provider->log($connection, $queue, $payload, $exception); } - $count = $database->selectCollection($collection)->count(); + $count = $database->selectCollection($collection)->countDocuments(); - $this->assertEquals(10, $count); + self::assertEquals(10, $count); $provider->flush(); - $count = $database->selectCollection($collection)->count(); + $count = $database->selectCollection($collection)->countDocuments(); - $this->assertEquals(0, $count); + self::assertEquals(0, $count); } /** @@ -161,9 +161,9 @@ private function mockProvider(Database $database, string $collection): MongoFail { $mongo = $this->createMock(MongoDriverInterface::class); $mongo - ->expects($this->any()) + ->expects(self::any()) ->method('getDatabase') - ->will($this->returnValue($database)); + ->willReturn($database); $provider = new MongoFailedJobProvider($mongo, $collection); diff --git a/Tests/Handler/ExceptionHandlerTest.php b/Tests/Handler/ExceptionHandlerTest.php index 8ddb626..cb9d405 100644 --- a/Tests/Handler/ExceptionHandlerTest.php +++ b/Tests/Handler/ExceptionHandlerTest.php @@ -41,9 +41,9 @@ private function mockLogger(Exception $exception): LoggerInterface { $logger = $this->createMock(LoggerInterface::class); $logger - ->expects($this->once()) + ->expects(self::once()) ->method('error') - ->with($this->equalTo($exception->getMessage()), $this->equalTo(['exception' => $exception])); + ->with(self::equalTo($exception->getMessage()), self::equalTo(['exception' => $exception])); return $logger; } diff --git a/Tests/Job/JobContractTest.php b/Tests/Job/JobContractTest.php index 1e45946..392eb8f 100644 --- a/Tests/Job/JobContractTest.php +++ b/Tests/Job/JobContractTest.php @@ -27,11 +27,11 @@ public function testJob() $job = $this->mockJob(); $contract = $this->mockJobContract($job); - $this->assertEquals($job->getId(), $contract->getJobId()); - $this->assertEquals($job->getAttempts(), $contract->attempts()); - $this->assertEquals($job->isReserved(), $contract->reserved()); - $this->assertEquals($job->getReservedAt(), $contract->reservedAt()); - $this->assertEquals($job->getPayload(), $contract->payload()); + self::assertEquals($job->getId(), $contract->getJobId()); + self::assertEquals($job->getAttempts(), $contract->attempts()); + self::assertEquals($job->isReserved(), $contract->reserved()); + self::assertEquals($job->getReservedAt(), $contract->reservedAt()); + self::assertEquals($job->getPayload(), $contract->payload()); } /** @@ -42,12 +42,12 @@ public function testJobPayload() $job = $this->mockJob(); $contract = $this->mockJobContract($job); - $this->assertEquals($job->getPayload(), $contract->payload()); - $this->assertEquals($job->getPayload()['job'], $contract->getName()); - $this->assertEquals($job->getPayload()['data'], $contract->getData()); - $this->assertEquals($job->getPayload()['maxTries'], $contract->maxTries()); - $this->assertEquals($job->getPayload()['timeout'], $contract->timeout()); - $this->assertEquals($job->getPayload()['timeoutAt'], $contract->timeoutAt()); + self::assertEquals($job->getPayload(), $contract->payload()); + self::assertEquals($job->getPayload()['job'], $contract->getName()); + self::assertEquals($job->getPayload()['data'], $contract->getData()); + self::assertEquals($job->getPayload()['maxTries'], $contract->maxTries()); + self::assertEquals($job->getPayload()['timeout'], $contract->timeout()); + self::assertEquals($job->getPayload()['timeoutAt'], $contract->timeoutAt()); } /** @@ -58,25 +58,25 @@ public function testContract() $job = $this->mockJob(); $contract = $this->mockJobContract($job); - $this->assertFalse($contract->isDeleted()); - $this->assertFalse($contract->isDeletedOrReleased()); + self::assertFalse($contract->isDeleted()); + self::assertFalse($contract->isDeletedOrReleased()); $contract->delete(); - $this->assertTrue($contract->isDeleted()); - $this->assertTrue($contract->isDeletedOrReleased()); + self::assertTrue($contract->isDeleted()); + self::assertTrue($contract->isDeletedOrReleased()); - $this->assertFalse($contract->isReleased()); + self::assertFalse($contract->isReleased()); $contract->release(); - $this->assertTrue($contract->isReleased()); + self::assertTrue($contract->isReleased()); - $this->assertFalse($contract->hasFailed()); + self::assertFalse($contract->hasFailed()); $contract->markAsFailed(); - $this->assertTrue($contract->hasFailed()); + self::assertTrue($contract->hasFailed()); } /** @@ -95,23 +95,23 @@ public function testActions() ]) ->getMock(); $jobInstance - ->expects($this->once()) + ->expects(self::once()) ->method('fire') - ->with($this->anything(), $this->equalTo($job->getPayload()['data'])); + ->with(self::anything(), self::equalTo($job->getPayload()['data'])); $jobInstance - ->expects($this->once()) + ->expects(self::once()) ->method('failed') - ->with($this->equalTo($job->getPayload()['data']), $this->equalTo($exception)); + ->with(self::equalTo($job->getPayload()['data']), self::equalTo($exception)); $contract = $this->mockJobContract($job, $jobInstance); $contract->fire(); - $this->assertFalse($contract->hasFailed()); + self::assertFalse($contract->hasFailed()); $contract->failed($exception); - $this->assertTrue($contract->hasFailed()); + self::assertTrue($contract->hasFailed()); } /** @@ -157,10 +157,10 @@ private function mockJobContract(Job $jobData, ?JobInterface $jobInstance = null $resolver = $this->createMock(JobResolverInterface::class); $resolver - ->expects($this->any()) + ->expects(self::any()) ->method('resolve') - ->with($this->equalTo($jobData->getPayload()['job'])) - ->will($this->returnValue($jobInstance)); + ->with(self::equalTo($jobData->getPayload()['job'])) + ->willReturn($jobInstance); $contract = $this->getMockBuilder(JobContract::class) ->setConstructorArgs([$resolver, $queue, $jobData, $queueName]) diff --git a/Tests/JobContract/JobContractTest.php b/Tests/JobContract/JobContractTest.php index ecd0bf5..5d9560a 100644 --- a/Tests/JobContract/JobContractTest.php +++ b/Tests/JobContract/JobContractTest.php @@ -27,11 +27,11 @@ public function testJob() $job = $this->mockJob(); $contract = $this->mockJobContract($job); - $this->assertEquals($job->getId(), $contract->getJobId()); - $this->assertEquals($job->getAttempts(), $contract->attempts()); - $this->assertEquals($job->isReserved(), $contract->reserved()); - $this->assertEquals($job->getReservedAt(), $contract->reservedAt()); - $this->assertEquals($job->getPayload(), $contract->payload()); + self::assertEquals($job->getId(), $contract->getJobId()); + self::assertEquals($job->getAttempts(), $contract->attempts()); + self::assertEquals($job->isReserved(), $contract->reserved()); + self::assertEquals($job->getReservedAt(), $contract->reservedAt()); + self::assertEquals($job->getPayload(), $contract->payload()); } /** @@ -42,12 +42,12 @@ public function testJobPayload() $job = $this->mockJob(); $contract = $this->mockJobContract($job); - $this->assertEquals($job->getPayload(), $contract->payload()); - $this->assertEquals($job->getPayload()['job'], $contract->getName()); - $this->assertEquals($job->getPayload()['data'], $contract->getData()); - $this->assertEquals($job->getPayload()['maxTries'], $contract->maxTries()); - $this->assertEquals($job->getPayload()['timeout'], $contract->timeout()); - $this->assertEquals($job->getPayload()['timeoutAt'], $contract->timeoutAt()); + self::assertEquals($job->getPayload(), $contract->payload()); + self::assertEquals($job->getPayload()['job'], $contract->getName()); + self::assertEquals($job->getPayload()['data'], $contract->getData()); + self::assertEquals($job->getPayload()['maxTries'], $contract->maxTries()); + self::assertEquals($job->getPayload()['timeout'], $contract->timeout()); + self::assertEquals($job->getPayload()['timeoutAt'], $contract->timeoutAt()); } /** @@ -58,25 +58,25 @@ public function testContract() $job = $this->mockJob(); $contract = $this->mockJobContract($job); - $this->assertFalse($contract->isDeleted()); - $this->assertFalse($contract->isDeletedOrReleased()); + self::assertFalse($contract->isDeleted()); + self::assertFalse($contract->isDeletedOrReleased()); $contract->delete(); - $this->assertTrue($contract->isDeleted()); - $this->assertTrue($contract->isDeletedOrReleased()); + self::assertTrue($contract->isDeleted()); + self::assertTrue($contract->isDeletedOrReleased()); - $this->assertFalse($contract->isReleased()); + self::assertFalse($contract->isReleased()); $contract->release(); - $this->assertTrue($contract->isReleased()); + self::assertTrue($contract->isReleased()); - $this->assertFalse($contract->hasFailed()); + self::assertFalse($contract->hasFailed()); $contract->markAsFailed(); - $this->assertTrue($contract->hasFailed()); + self::assertTrue($contract->hasFailed()); } /** @@ -95,23 +95,23 @@ public function testActions() ]) ->getMock(); $jobInstance - ->expects($this->once()) + ->expects(self::once()) ->method('fire') - ->with($this->anything(), $this->equalTo($job->getPayload()['data'])); + ->with(self::anything(), self::equalTo($job->getPayload()['data'])); $jobInstance - ->expects($this->once()) + ->expects(self::once()) ->method('failed') - ->with($this->equalTo($job->getPayload()['data']), $this->equalTo($exception)); + ->with(self::equalTo($job->getPayload()['data']), self::equalTo($exception)); $contract = $this->mockJobContract($job, $jobInstance); $contract->fire(); - $this->assertFalse($contract->hasFailed()); + self::assertFalse($contract->hasFailed()); $contract->failed($exception); - $this->assertTrue($contract->hasFailed()); + self::assertTrue($contract->hasFailed()); } /** @@ -141,7 +141,7 @@ private function mockJob(): Job /** * Mock mongo job contract * - * @param Job $job + * @param Job $jobData * @param JobInterface|null $jobInstance * * @return JobContract @@ -157,10 +157,10 @@ private function mockJobContract(Job $jobData, ?JobInterface $jobInstance = null $resolver = $this->createMock(JobResolverInterface::class); $resolver - ->expects($this->any()) + ->expects(self::any()) ->method('resolve') - ->with($this->equalTo($jobData->getPayload()['job'])) - ->will($this->returnValue($jobInstance)); + ->with(self::equalTo($jobData->getPayload()['job'])) + ->willReturn($jobInstance); $contract = $this->getMockBuilder(JobContract::class) ->setConstructorArgs([$resolver, $queue, $jobData, $queueName]) diff --git a/Tests/Queue/MongoQueueTest.php b/Tests/Queue/MongoQueueTest.php index 1603ca2..fe8fa02 100644 --- a/Tests/Queue/MongoQueueTest.php +++ b/Tests/Queue/MongoQueueTest.php @@ -36,13 +36,13 @@ public function testPush() $mongoQueue->push($jobName, $data); - $this->assertEquals(1, $database->selectCollection($collection)->count()); + self::assertEquals(1, $database->selectCollection($collection)->count()); $job = $database->selectCollection($collection)->findOne(); $payload = json_decode($job->payload, true); - $this->assertEquals($jobName, $payload['job']); - $this->assertEquals($data, $payload['data']); + self::assertEquals($jobName, $payload['job']); + self::assertEquals($data, $payload['data']); } /** @@ -61,8 +61,8 @@ public function testPop() $mongoQueue->push($jobName, $data); $job = $mongoQueue->pop(); - $this->assertEquals($jobName, $job->getName()); - $this->assertEquals($data, $job->payload()['data']); + self::assertEquals($jobName, $job->getName()); + self::assertEquals($data, $job->payload()['data']); } /** @@ -80,7 +80,7 @@ public function testExists() $mongoQueue->push($jobName, $data); - $this->assertTrue($mongoQueue->exists($jobName, $data)); + self::assertTrue($mongoQueue->exists($jobName, $data)); } /** @@ -98,13 +98,13 @@ public function testPushOn() $mongoQueue->pushOn('default', $jobName, $data); - $this->assertEquals(1, $database->selectCollection($collection)->count()); + self::assertEquals(1, $database->selectCollection($collection)->count()); $job = $database->selectCollection($collection)->findOne(); $payload = json_decode($job->payload, true); - $this->assertEquals($jobName, $payload['job']); - $this->assertEquals($data, $payload['data']); + self::assertEquals($jobName, $payload['job']); + self::assertEquals($data, $payload['data']); } /** @@ -123,13 +123,13 @@ public function testPushRaw() $mongoQueue->pushRaw(json_encode(['job' => $jobName, 'data' => $data])); $count = $database->selectCollection($collection)->count(); - $this->assertEquals(1, $count); + self::assertEquals(1, $count); $job = $database->selectCollection($collection)->findOne(); $payload = json_decode($job->payload, true); - $this->assertEquals($jobName, $payload['job']); - $this->assertEquals($data, $payload['data']); + self::assertEquals($jobName, $payload['job']); + self::assertEquals($data, $payload['data']); } /** @@ -151,10 +151,10 @@ public function testLater() $job = $database->selectCollection($collection)->findOne(); $payload = json_decode($job->payload, true); - $this->assertEquals($jobName, $payload['job']); - $this->assertEquals($data, $payload['data']); + self::assertEquals($jobName, $payload['job']); + self::assertEquals($data, $payload['data']); - $this->assertGreaterThan(time() + $delay - 10, $job->available_at); + self::assertGreaterThan(time() + $delay - 10, $job->available_at); } /** @@ -179,7 +179,7 @@ public function testBulk() $count = $database->selectCollection($collection)->count(); - $this->assertEquals(10, $count); + self::assertEquals(10, $count); } /** @@ -214,7 +214,7 @@ public function testRelease() $count = $database->selectCollection($collection)->count(); - $this->assertEquals(1, $count); + self::assertEquals(1, $count); } /** @@ -236,8 +236,8 @@ public function testGetJobById() $jobContract = $mongoQueue->getJobById($job->_id); - $this->assertInstanceOf(JobContractInterface::class, $jobContract); - $this->assertEquals($jobContract->getName(), $jobName); + self::assertInstanceOf(JobContractInterface::class, $jobContract); + self::assertEquals($jobContract->getName(), $jobName); } /** @@ -257,16 +257,16 @@ public function testDeleteReserved() $count = $database->selectCollection($collection)->count(); - $this->assertEquals(1, $count); + self::assertEquals(1, $count); $job = $database->selectCollection($collection)->findOne(); $result = $mongoQueue->deleteReserved($job->queue, $job->_id); - $this->assertTrue($result); + self::assertTrue($result); $count = $database->selectCollection($collection)->count(); - $this->assertEquals(0, $count); + self::assertEquals(0, $count); } /** @@ -283,7 +283,7 @@ public function testExpire() $mongoQueue->setExpire($expire); - $this->assertEquals($expire, $mongoQueue->getExpire()); + self::assertEquals($expire, $mongoQueue->getExpire()); } /** @@ -307,8 +307,8 @@ public function testSize() $count = $database->selectCollection($collection)->count(); - $this->assertEquals($count, $mongoQueue->size()); - $this->assertEquals($count, $mongoQueue->size($job->queue)); + self::assertEquals($count, $mongoQueue->size()); + self::assertEquals($count, $mongoQueue->size($job->queue)); } /** @@ -333,7 +333,7 @@ public function testCanRunJob() $canRun = $mongoQueue->canRunJob($jobContract); - $this->assertTrue($canRun); + self::assertTrue($canRun); } /** @@ -361,9 +361,9 @@ public function testMarkJobAsReserved() $reservedJob = $database->selectCollection($collection)->findOne(); - $this->assertTrue((bool)$reservedJob->reserved); - $this->assertGreaterThan($attempts, $reservedJob->attempts); - $this->assertNotNull($reservedJob->reserved_at); + self::assertTrue((bool)$reservedJob->reserved); + self::assertGreaterThan($attempts, $reservedJob->attempts); + self::assertNotNull($reservedJob->reserved_at); } /** @@ -379,9 +379,9 @@ private function mockMongoQueue(Database $database, string $collection): MongoQu $jobResolver = $this->createMock(JobResolverInterface::class); $mongo = $this->createMock(MongoDriverInterface::class); $mongo - ->expects($this->any()) + ->expects(self::any()) ->method('getDatabase') - ->will($this->returnValue($database)); + ->willReturn($database); $mongoQueue = new MongoQueue($jobResolver, $mongo, $collection); diff --git a/Tests/Service/JobProcessTest.php b/Tests/Service/JobProcessTest.php index 86432e9..069ce15 100644 --- a/Tests/Service/JobProcessTest.php +++ b/Tests/Service/JobProcessTest.php @@ -23,23 +23,21 @@ public function testGetProcess() { $scriptName = uniqid('script_'); $binPath = __DIR__; - $binary = 'php'; - $binaryArgs = ''; - $jobProcess = new JobProcess($scriptName, $binPath, $binary, $binaryArgs); + $jobProcess = new JobProcess($scriptName, $binPath); $jobId = uniqid('id_'); $jobQueue = uniqid('queue_'); $job = $this->createMock(JobContractInterface::class); $job - ->expects($this->exactly(2)) + ->expects(self::exactly(2)) ->method('getJobId') - ->will($this->returnValue($jobId)); + ->willReturn($jobId); $job - ->expects($this->exactly(2)) + ->expects(self::exactly(2)) ->method('getQueue') - ->will($this->returnValue($jobQueue)); + ->willReturn($jobQueue); $connectionName = uniqid('connection_'); @@ -49,8 +47,8 @@ public function testGetProcess() $process = $jobProcess->getProcess($job, new Options()); - $command = sprintf("'php' %s job-queue:run-job %s --connection=%s --queue=%s --env=%s --delay=0 --memory=128 --timeout=60 --sleep=3 --maxTries=0 > /dev/null 2>&1 &", $scriptName, $job->getJobId(), $connectionName, $job->getQueue(), getenv('APP_ENV')); + $command = sprintf("'%s' '%s' 'job-queue:run-job' '%s' '--connection=%s' '--queue=%s' '--env=%s' '--delay=0' '--memory=128' '--timeout=60' '--sleep=3' '--maxTries=0' ' > /dev/null 2>&1 &'", 'php', $scriptName, $job->getJobId(), $connectionName, $job->getQueue(), 'prod'); - $this->assertEquals($command, $process->getCommandLine()); + self::assertEquals($command, $process->getCommandLine()); } } diff --git a/Tests/Service/JobQueueTest.php b/Tests/Service/JobQueueTest.php index 08060eb..af46d80 100644 --- a/Tests/Service/JobQueueTest.php +++ b/Tests/Service/JobQueueTest.php @@ -40,14 +40,14 @@ public function testPush() $manager = $this->mockManager(); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('push') ->with($job, $data, $queue, $connection) - ->will($this->returnValue(true)); + ->willReturn(true); $jobQueue = $this->mockJobQueue($manager); - $this->assertTrue($jobQueue->push($job, $data, $queue, $connection)); + self::assertTrue($jobQueue->push($job, $data, $queue, $connection)); } /** @@ -62,44 +62,44 @@ public function testPushUnique() $connectionMock = $this->createMock(QueueInterface::class); $connectionMock - ->expects($this->once()) + ->expects(self::once()) ->method('exists') - ->with($this->equalTo($job), $this->equalTo($data), $this->equalTo($queue)) - ->will($this->returnValue(false)); + ->with(self::equalTo($job), self::equalTo($data), self::equalTo($queue)) + ->willReturn(false); $manager = $this->mockManager(); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('connection') - ->with($this->equalTo($connection)) - ->will($this->returnValue($connectionMock)); + ->with(self::equalTo($connection)) + ->willReturn($connectionMock); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('push') ->with($job, $data, $queue, $connection) - ->will($this->returnValue(true)); + ->willReturn(true); $jobQueue = $this->mockJobQueue($manager); - $this->assertTrue($jobQueue->pushUnique($job, $data, $queue, $connection)); + self::assertTrue($jobQueue->pushUnique($job, $data, $queue, $connection)); $connectionMock = $this->createMock(QueueInterface::class); $connectionMock - ->expects($this->once()) + ->expects(self::once()) ->method('exists') - ->with($this->equalTo($job), $this->equalTo($data), $this->equalTo($queue)) - ->will($this->returnValue(true)); + ->with(self::equalTo($job), self::equalTo($data), self::equalTo($queue)) + ->willReturn(true); $manager = $this->mockManager(); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('connection') - ->with($this->equalTo($connection)) - ->will($this->returnValue($connectionMock)); + ->with(self::equalTo($connection)) + ->willReturn($connectionMock); $jobQueue = $this->mockJobQueue($manager); - $this->assertNull($jobQueue->pushUnique($job, $data, $queue, $connection)); + self::assertNull($jobQueue->pushUnique($job, $data, $queue, $connection)); } /** @@ -119,14 +119,14 @@ public function testBulk() $manager = $this->mockManager(); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('bulk') ->with($jobs, $data, $queue, $connection) - ->will($this->returnValue(true)); + ->willReturn(true); $jobQueue = $this->mockJobQueue($manager); - $this->assertTrue($jobQueue->bulk($jobs, $data, $queue, $connection)); + self::assertTrue($jobQueue->bulk($jobs, $data, $queue, $connection)); } /** @@ -142,14 +142,14 @@ public function testLater() $manager = $this->mockManager(); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('later') ->with($delay, $job, $data, $queue, $connection) - ->will($this->returnValue(true)); + ->willReturn(true); $jobQueue = $this->mockJobQueue($manager); - $this->assertTrue($jobQueue->later($delay, $job, $data, $queue, $connection)); + self::assertTrue($jobQueue->later($delay, $job, $data, $queue, $connection)); } /** @@ -165,44 +165,44 @@ public function testLaterUnique() $connectionMock = $this->createMock(QueueInterface::class); $connectionMock - ->expects($this->once()) + ->expects(self::once()) ->method('exists') - ->with($this->equalTo($job), $this->equalTo($data), $this->equalTo($queue)) - ->will($this->returnValue(false)); + ->with(self::equalTo($job), self::equalTo($data), self::equalTo($queue)) + ->willReturn(false); $manager = $this->mockManager(); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('connection') - ->with($this->equalTo($connection)) - ->will($this->returnValue($connectionMock)); + ->with(self::equalTo($connection)) + ->willReturn($connectionMock); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('later') ->with($delay, $job, $data, $queue, $connection) - ->will($this->returnValue(true)); + ->willReturn(true); $jobQueue = $this->mockJobQueue($manager); - $this->assertTrue($jobQueue->laterUnique($delay, $job, $data, $queue, $connection)); + self::assertTrue($jobQueue->laterUnique($delay, $job, $data, $queue, $connection)); $connectionMock = $this->createMock(QueueInterface::class); $connectionMock - ->expects($this->once()) + ->expects(self::once()) ->method('exists') - ->with($this->equalTo($job), $this->equalTo($data), $this->equalTo($queue)) - ->will($this->returnValue(true)); + ->with(self::equalTo($job), self::equalTo($data), self::equalTo($queue)) + ->willReturn(true); $manager = $this->mockManager(); $manager - ->expects($this->once()) + ->expects(self::once()) ->method('connection') - ->with($this->equalTo($connection)) - ->will($this->returnValue($connectionMock)); + ->with(self::equalTo($connection)) + ->willReturn($connectionMock); $jobQueue = $this->mockJobQueue($manager); - $this->assertNull($jobQueue->laterUnique($delay, $job, $data, $queue, $connection)); + self::assertNull($jobQueue->laterUnique($delay, $job, $data, $queue, $connection)); } /** diff --git a/Tests/Service/JobResolverTest.php b/Tests/Service/JobResolverTest.php index 2fd626c..5a9bb5a 100644 --- a/Tests/Service/JobResolverTest.php +++ b/Tests/Service/JobResolverTest.php @@ -5,7 +5,6 @@ use PHPUnit\Framework\TestCase; use SfCod\QueueBundle\Base\JobInterface; use SfCod\QueueBundle\Service\JobResolver; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Class JobResolverTest @@ -27,23 +26,6 @@ public function testResolve() $resolver = new JobResolver(); $resolver->addJob($jobName, $jobClass); - $this->assertEquals($jobClass, $resolver->resolve($jobName)); - } - - /** - * Mock resolver - * - * @param ContainerInterface $container - * - * @return JobResolver - */ - private function mockResolver(ContainerInterface $container): JobResolver - { - $resolver = $this->getMockBuilder(JobResolver::class) -// ->setConstructorArgs([$container]) - ->setMethods(null) - ->getMock(); - - return $resolver; + self::assertEquals($jobClass, $resolver->resolve($jobName)); } } diff --git a/Tests/Service/MongoDriverTest.php b/Tests/Service/MongoDriverTest.php index 47f510b..32176f7 100644 --- a/Tests/Service/MongoDriverTest.php +++ b/Tests/Service/MongoDriverTest.php @@ -29,11 +29,11 @@ public function testDriver() $driver = new MongoDriver(); $driver->setCredentials($uri, $uriOptions, $driverOptions); - $this->assertInstanceOf(Client::class, $driver->getClient()); + self::assertInstanceOf(Client::class, $driver->getClient()); $driver->setDbname($dbName); - $this->assertInstanceOf(Database::class, $driver->getDatabase()); - $this->assertEquals($dbName, $driver->getDatabase()->getDatabaseName()); + self::assertInstanceOf(Database::class, $driver->getDatabase()); + self::assertEquals($dbName, $driver->getDatabase()->getDatabaseName()); } } diff --git a/Tests/Service/QueueManagerTest.php b/Tests/Service/QueueManagerTest.php index 3ddfb56..aa05876 100644 --- a/Tests/Service/QueueManagerTest.php +++ b/Tests/Service/QueueManagerTest.php @@ -26,12 +26,12 @@ public function testConnection() $queueManager = $this->mockQueueManager($driver, $connectionName); - $this->assertFalse($queueManager->connected($connectionName)); + self::assertFalse($queueManager->connected($connectionName)); $queue = $queueManager->connection($connectionName); - $this->assertInstanceOf(QueueInterface::class, $queue); - $this->assertTrue($queueManager->connected($connectionName)); + self::assertInstanceOf(QueueInterface::class, $queue); + self::assertTrue($queueManager->connected($connectionName)); } /** @@ -54,17 +54,17 @@ private function mockQueueManager(string $driver, string $connectionName): Queue $queue = $this->createMock(QueueInterface::class); $queue - ->expects($this->once()) + ->expects(self::once()) ->method('setConnectionName') - ->with($this->equalTo($connectionName)) - ->will($this->returnSelf()); + ->with(self::equalTo($connectionName)) + ->will(self::returnSelf()); $connector = $this->createMock(ConnectorInterface::class); $connector - ->expects($this->once()) + ->expects(self::once()) ->method('connect') - ->with($this->equalTo($config)) - ->will($this->returnValue($queue)); + ->with(self::equalTo($config)) + ->willReturn($queue); $queueManager = new QueueManager(); diff --git a/Worker/Worker.php b/Worker/Worker.php index 76edddf..b03c308 100644 --- a/Worker/Worker.php +++ b/Worker/Worker.php @@ -46,7 +46,7 @@ class Worker /** * Logger instance * - * @var ExceptionHandler + * @var ExceptionHandlerInterface */ private $exceptions; @@ -65,12 +65,12 @@ class Worker /** * @var JobProcess */ - private $jobProcess; + private $process; /** * Worker constructor. * - * @param QueueInterface $queue + * @param QueueManager $queueManager * @param JobProcess $process * @param FailedJobProviderInterface $failer * @param ExceptionHandlerInterface $exceptions @@ -246,12 +246,10 @@ public function memoryExceeded(int $memoryLimit) /** * Stop listening and bail out of the script. - * - * @param int $status */ - public function stop(int $status = 0) + public function stop() { - $this->dispatcher->dispatch(self::EVENT_STOP, new WorkerStoppingEvent()); + $this->dispatcher->dispatch(new WorkerStoppingEvent(), self::EVENT_STOP); exit(0); } @@ -409,7 +407,7 @@ protected function getNextJob(QueueInterface $connection, string $queue): ?JobCo */ protected function raiseBeforeJobEvent(string $connectionName, JobContractInterface $job) { - $this->dispatcher->dispatch(self::EVENT_RAISE_AFTER_JOB, new JobProcessingEvent($connectionName, $job)); + $this->dispatcher->dispatch(new JobProcessingEvent($connectionName, $job), self::EVENT_RAISE_AFTER_JOB); } /** @@ -420,7 +418,7 @@ protected function raiseBeforeJobEvent(string $connectionName, JobContractInterf */ protected function raiseAfterJobEvent(string $connectionName, JobContractInterface $job) { - $this->dispatcher->dispatch(self::EVENT_RAISE_AFTER_JOB, new JobProcessedEvent($connectionName, $job)); + $this->dispatcher->dispatch(new JobProcessedEvent($connectionName, $job), self::EVENT_RAISE_AFTER_JOB); } /** @@ -432,7 +430,7 @@ protected function raiseAfterJobEvent(string $connectionName, JobContractInterfa */ protected function raiseExceptionOccurredJobEvent(string $connectionName, JobContractInterface $job, Exception $e) { - $this->dispatcher->dispatch(self::EVENT_RAISE_EXCEPTION_OCCURED_JOB, new JobExceptionOccurredEvent($connectionName, $job, $e)); + $this->dispatcher->dispatch(new JobExceptionOccurredEvent($connectionName, $job, $e), self::EVENT_RAISE_EXCEPTION_OCCURED_JOB); } /** @@ -444,6 +442,6 @@ protected function raiseExceptionOccurredJobEvent(string $connectionName, JobCon */ protected function raiseFailedJobEvent(string $connectionName, JobContractInterface $job, Exception $e) { - $this->dispatcher->dispatch(self::EVENT_RAISE_FAILED_JOB, new JobFailedEvent($connectionName, $job, $e)); + $this->dispatcher->dispatch(new JobFailedEvent($connectionName, $job, $e), self::EVENT_RAISE_FAILED_JOB); } } diff --git a/composer.json b/composer.json index 347b49f..d4e5026 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,14 @@ ], "require": { "php": "^7.1", - "symfony/framework-bundle": "^4.0", + "symfony/framework-bundle": "^4.4 || ^5.0", "mongodb/mongodb": "^1.1", "symfony/monolog-bundle": "^3.1", - "symfony/process": "^4.0", - "symfony/dotenv": "^4.0" + "symfony/process": "^4.4 || ^5.0", + "symfony/dotenv": "^4.4 || ^5.0" }, "require-dev": { - "symfony/phpunit-bridge": "^4.0", + "symfony/phpunit-bridge": "^4.4 || ^5.0", "friendsofphp/php-cs-fixer": "^2.8", "helmich/mongomock": "^2.1", "phpunit/phpunit": "^7.5"