From 1eb5bb902d44bb7f95b5a4d18a168fb261947d16 Mon Sep 17 00:00:00 2001 From: Stas Pavlovichev Date: Sun, 6 Aug 2017 16:50:04 +0300 Subject: [PATCH] Using `dispatch` instead of `fire` according to \Illuminate\Contracts\Events\Dispatcher (#20446) --- src/Illuminate/Queue/FailingJob.php | 2 +- src/Illuminate/Queue/SyncQueue.php | 6 +++--- src/Illuminate/Queue/Worker.php | 10 +++++----- tests/Queue/QueueSyncQueueTest.php | 2 +- tests/Queue/QueueWorkerTest.php | 20 ++++++++++---------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Illuminate/Queue/FailingJob.php b/src/Illuminate/Queue/FailingJob.php index 1102d9f8459c..aba6f1720af7 100644 --- a/src/Illuminate/Queue/FailingJob.php +++ b/src/Illuminate/Queue/FailingJob.php @@ -32,7 +32,7 @@ public static function handle($connectionName, $job, $e = null) $job->failed($e); } finally { - static::events()->fire(new JobFailed( + static::events()->dispatch(new JobFailed( $connectionName, $job, $e ?: new ManuallyFailedException )); } diff --git a/src/Illuminate/Queue/SyncQueue.php b/src/Illuminate/Queue/SyncQueue.php index c2fcd24e6f0d..21bd113580af 100755 --- a/src/Illuminate/Queue/SyncQueue.php +++ b/src/Illuminate/Queue/SyncQueue.php @@ -72,7 +72,7 @@ protected function resolveJob($payload, $queue) protected function raiseBeforeJobEvent(Job $job) { if ($this->container->bound('events')) { - $this->container['events']->fire(new Events\JobProcessing($this->connectionName, $job)); + $this->container['events']->dispatch(new Events\JobProcessing($this->connectionName, $job)); } } @@ -85,7 +85,7 @@ protected function raiseBeforeJobEvent(Job $job) protected function raiseAfterJobEvent(Job $job) { if ($this->container->bound('events')) { - $this->container['events']->fire(new Events\JobProcessed($this->connectionName, $job)); + $this->container['events']->dispatch(new Events\JobProcessed($this->connectionName, $job)); } } @@ -99,7 +99,7 @@ protected function raiseAfterJobEvent(Job $job) protected function raiseExceptionOccurredJobEvent(Job $job, $e) { if ($this->container->bound('events')) { - $this->container['events']->fire(new Events\JobExceptionOccurred($this->connectionName, $job, $e)); + $this->container['events']->dispatch(new Events\JobExceptionOccurred($this->connectionName, $job, $e)); } } diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 3e3c096d4bae..7dcd258afedb 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -429,7 +429,7 @@ protected function failJob($connectionName, $job, $e) */ protected function raiseBeforeJobEvent($connectionName, $job) { - $this->events->fire(new Events\JobProcessing( + $this->events->dispatch(new Events\JobProcessing( $connectionName, $job )); } @@ -443,7 +443,7 @@ protected function raiseBeforeJobEvent($connectionName, $job) */ protected function raiseAfterJobEvent($connectionName, $job) { - $this->events->fire(new Events\JobProcessed( + $this->events->dispatch(new Events\JobProcessed( $connectionName, $job )); } @@ -458,7 +458,7 @@ protected function raiseAfterJobEvent($connectionName, $job) */ protected function raiseExceptionOccurredJobEvent($connectionName, $job, $e) { - $this->events->fire(new Events\JobExceptionOccurred( + $this->events->dispatch(new Events\JobExceptionOccurred( $connectionName, $job, $e )); } @@ -473,7 +473,7 @@ protected function raiseExceptionOccurredJobEvent($connectionName, $job, $e) */ protected function raiseFailedJobEvent($connectionName, $job, $e) { - $this->events->fire(new Events\JobFailed( + $this->events->dispatch(new Events\JobFailed( $connectionName, $job, $e )); } @@ -555,7 +555,7 @@ public function memoryExceeded($memoryLimit) */ public function stop($status = 0) { - $this->events->fire(new Events\WorkerStopping); + $this->events->dispatch(new Events\WorkerStopping); exit($status); } diff --git a/tests/Queue/QueueSyncQueueTest.php b/tests/Queue/QueueSyncQueueTest.php index 18540f641142..5a60f3da2cf9 100755 --- a/tests/Queue/QueueSyncQueueTest.php +++ b/tests/Queue/QueueSyncQueueTest.php @@ -35,7 +35,7 @@ public function testFailedJobGetsHandledWhenAnExceptionIsThrown() $container = new \Illuminate\Container\Container; Container::setInstance($container); $events = m::mock('Illuminate\Contracts\Events\Dispatcher'); - $events->shouldReceive('fire')->times(3); + $events->shouldReceive('dispatch')->times(3); $container->instance('events', $events); $container->instance('Illuminate\Contracts\Events\Dispatcher', $events); $sync->setContainer($container); diff --git a/tests/Queue/QueueWorkerTest.php b/tests/Queue/QueueWorkerTest.php index 49cc2a97574d..f4900f010b2c 100755 --- a/tests/Queue/QueueWorkerTest.php +++ b/tests/Queue/QueueWorkerTest.php @@ -41,8 +41,8 @@ public function test_job_can_be_fired() $worker = $this->getWorker('default', ['queue' => [$job = new WorkerFakeJob]]); $worker->runNextJob('default', 'queue', new WorkerOptions); $this->assertTrue($job->fired); - $this->events->shouldHaveReceived('fire')->with(Mockery::type(JobProcessing::class))->once(); - $this->events->shouldHaveReceived('fire')->with(Mockery::type(JobProcessed::class))->once(); + $this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobProcessing::class))->once(); + $this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobProcessed::class))->once(); } public function test_job_can_be_fired_based_on_priority() @@ -98,8 +98,8 @@ public function test_job_is_released_on_exception() $this->assertEquals(10, $job->releaseAfter); $this->assertFalse($job->deleted); $this->exceptionHandler->shouldHaveReceived('report')->with($e); - $this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once(); - $this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]); + $this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once(); + $this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]); } public function test_job_is_not_released_if_it_has_exceeded_max_attempts() @@ -121,9 +121,9 @@ public function test_job_is_not_released_if_it_has_exceeded_max_attempts() $this->assertTrue($job->deleted); $this->assertEquals($e, $job->failedWith); $this->exceptionHandler->shouldHaveReceived('report')->with($e); - $this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once(); - $this->events->shouldHaveReceived('fire')->with(Mockery::type(JobFailed::class))->once(); - $this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]); + $this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once(); + $this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobFailed::class))->once(); + $this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]); } public function test_job_is_failed_if_it_has_already_exceeded_max_attempts() @@ -141,9 +141,9 @@ public function test_job_is_failed_if_it_has_already_exceeded_max_attempts() $this->assertTrue($job->deleted); $this->assertInstanceOf(MaxAttemptsExceededException::class, $job->failedWith); $this->exceptionHandler->shouldHaveReceived('report')->with(Mockery::type(MaxAttemptsExceededException::class)); - $this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once(); - $this->events->shouldHaveReceived('fire')->with(Mockery::type(JobFailed::class))->once(); - $this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]); + $this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once(); + $this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobFailed::class))->once(); + $this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]); } public function test_job_based_max_retries()