Skip to content

Commit

Permalink
allow chaining from helper
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 19, 2017
1 parent f7ba54c commit 91f5357
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Foundation/Bus/PendingDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Foundation\Bus;

use Illuminate\Contracts\Bus\Dispatcher;

class PendingDispatch
{
/**
Expand Down Expand Up @@ -74,6 +76,6 @@ public function chain($chain)
*/
public function __destruct()
{
dispatch($this->job);
app(Dispatcher::class)->dispatch($this->job);
}
}
5 changes: 3 additions & 2 deletions src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Foundation\Bus\PendingDispatch;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Contracts\Auth\Factory as AuthFactory;
use Illuminate\Contracts\View\Factory as ViewFactory;
Expand Down Expand Up @@ -368,11 +369,11 @@ function decrypt($value)
* Dispatch a job to its appropriate handler.
*
* @param mixed $job
* @return mixed
* @return \Illuminate\Foundation\Bus\PendingDispatch
*/
function dispatch($job)
{
return app(Dispatcher::class)->dispatch($job);
return new PendingDispatch($job);
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Integration/Queue/JobChainingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public function test_jobs_can_be_chained_on_success()
$this->assertTrue(JobChainingTestSecondJob::$ran);
}

public function test_jobs_can_be_chained_on_success_using_helper()
{
dispatch(new JobChainingTestFirstJob)->chain([
new JobChainingTestSecondJob,
]);

$this->assertTrue(JobChainingTestFirstJob::$ran);
$this->assertTrue(JobChainingTestSecondJob::$ran);
}

public function test_jobs_can_be_chained_via_queue()
{
Queue::connection('sync')->push((new JobChainingTestFirstJob)->chain([
Expand Down

0 comments on commit 91f5357

Please sign in to comment.