Skip to content

Commit 1eb5bb9

Browse files
fr05t1ktaylorotwell
authored andcommitted
Using dispatch instead of fire according to \Illuminate\Contracts\Events\Dispatcher (#20446)
1 parent c912bf4 commit 1eb5bb9

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

src/Illuminate/Queue/FailingJob.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function handle($connectionName, $job, $e = null)
3232

3333
$job->failed($e);
3434
} finally {
35-
static::events()->fire(new JobFailed(
35+
static::events()->dispatch(new JobFailed(
3636
$connectionName, $job, $e ?: new ManuallyFailedException
3737
));
3838
}

src/Illuminate/Queue/SyncQueue.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function resolveJob($payload, $queue)
7272
protected function raiseBeforeJobEvent(Job $job)
7373
{
7474
if ($this->container->bound('events')) {
75-
$this->container['events']->fire(new Events\JobProcessing($this->connectionName, $job));
75+
$this->container['events']->dispatch(new Events\JobProcessing($this->connectionName, $job));
7676
}
7777
}
7878

@@ -85,7 +85,7 @@ protected function raiseBeforeJobEvent(Job $job)
8585
protected function raiseAfterJobEvent(Job $job)
8686
{
8787
if ($this->container->bound('events')) {
88-
$this->container['events']->fire(new Events\JobProcessed($this->connectionName, $job));
88+
$this->container['events']->dispatch(new Events\JobProcessed($this->connectionName, $job));
8989
}
9090
}
9191

@@ -99,7 +99,7 @@ protected function raiseAfterJobEvent(Job $job)
9999
protected function raiseExceptionOccurredJobEvent(Job $job, $e)
100100
{
101101
if ($this->container->bound('events')) {
102-
$this->container['events']->fire(new Events\JobExceptionOccurred($this->connectionName, $job, $e));
102+
$this->container['events']->dispatch(new Events\JobExceptionOccurred($this->connectionName, $job, $e));
103103
}
104104
}
105105

src/Illuminate/Queue/Worker.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ protected function failJob($connectionName, $job, $e)
429429
*/
430430
protected function raiseBeforeJobEvent($connectionName, $job)
431431
{
432-
$this->events->fire(new Events\JobProcessing(
432+
$this->events->dispatch(new Events\JobProcessing(
433433
$connectionName, $job
434434
));
435435
}
@@ -443,7 +443,7 @@ protected function raiseBeforeJobEvent($connectionName, $job)
443443
*/
444444
protected function raiseAfterJobEvent($connectionName, $job)
445445
{
446-
$this->events->fire(new Events\JobProcessed(
446+
$this->events->dispatch(new Events\JobProcessed(
447447
$connectionName, $job
448448
));
449449
}
@@ -458,7 +458,7 @@ protected function raiseAfterJobEvent($connectionName, $job)
458458
*/
459459
protected function raiseExceptionOccurredJobEvent($connectionName, $job, $e)
460460
{
461-
$this->events->fire(new Events\JobExceptionOccurred(
461+
$this->events->dispatch(new Events\JobExceptionOccurred(
462462
$connectionName, $job, $e
463463
));
464464
}
@@ -473,7 +473,7 @@ protected function raiseExceptionOccurredJobEvent($connectionName, $job, $e)
473473
*/
474474
protected function raiseFailedJobEvent($connectionName, $job, $e)
475475
{
476-
$this->events->fire(new Events\JobFailed(
476+
$this->events->dispatch(new Events\JobFailed(
477477
$connectionName, $job, $e
478478
));
479479
}
@@ -555,7 +555,7 @@ public function memoryExceeded($memoryLimit)
555555
*/
556556
public function stop($status = 0)
557557
{
558-
$this->events->fire(new Events\WorkerStopping);
558+
$this->events->dispatch(new Events\WorkerStopping);
559559

560560
exit($status);
561561
}

tests/Queue/QueueSyncQueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testFailedJobGetsHandledWhenAnExceptionIsThrown()
3535
$container = new \Illuminate\Container\Container;
3636
Container::setInstance($container);
3737
$events = m::mock('Illuminate\Contracts\Events\Dispatcher');
38-
$events->shouldReceive('fire')->times(3);
38+
$events->shouldReceive('dispatch')->times(3);
3939
$container->instance('events', $events);
4040
$container->instance('Illuminate\Contracts\Events\Dispatcher', $events);
4141
$sync->setContainer($container);

tests/Queue/QueueWorkerTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function test_job_can_be_fired()
4141
$worker = $this->getWorker('default', ['queue' => [$job = new WorkerFakeJob]]);
4242
$worker->runNextJob('default', 'queue', new WorkerOptions);
4343
$this->assertTrue($job->fired);
44-
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobProcessing::class))->once();
45-
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobProcessed::class))->once();
44+
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobProcessing::class))->once();
45+
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobProcessed::class))->once();
4646
}
4747

4848
public function test_job_can_be_fired_based_on_priority()
@@ -98,8 +98,8 @@ public function test_job_is_released_on_exception()
9898
$this->assertEquals(10, $job->releaseAfter);
9999
$this->assertFalse($job->deleted);
100100
$this->exceptionHandler->shouldHaveReceived('report')->with($e);
101-
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once();
102-
$this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]);
101+
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once();
102+
$this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]);
103103
}
104104

105105
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()
121121
$this->assertTrue($job->deleted);
122122
$this->assertEquals($e, $job->failedWith);
123123
$this->exceptionHandler->shouldHaveReceived('report')->with($e);
124-
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once();
125-
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobFailed::class))->once();
126-
$this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]);
124+
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once();
125+
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobFailed::class))->once();
126+
$this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]);
127127
}
128128

129129
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()
141141
$this->assertTrue($job->deleted);
142142
$this->assertInstanceOf(MaxAttemptsExceededException::class, $job->failedWith);
143143
$this->exceptionHandler->shouldHaveReceived('report')->with(Mockery::type(MaxAttemptsExceededException::class));
144-
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once();
145-
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobFailed::class))->once();
146-
$this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]);
144+
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once();
145+
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobFailed::class))->once();
146+
$this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]);
147147
}
148148

149149
public function test_job_based_max_retries()

0 commit comments

Comments
 (0)