-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Added custom methods proxy support for jobs ::dispatch() (#34781)
* Added custom methods proxy * Fixed return * Update PendingDispatch.php Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
9c04734
commit 158c43c
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Queue; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class JobDispatchingTest extends TestCase | ||
{ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('app.debug', 'true'); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
Job::$ran = false; | ||
} | ||
|
||
public function testJobCanUseCustomMethodsAfterDispatch() | ||
{ | ||
Job::dispatch('test')->replaceValue('new-test'); | ||
|
||
$this->assertTrue(Job::$ran); | ||
$this->assertEquals('new-test', Job::$value); | ||
} | ||
} | ||
|
||
class Job implements ShouldQueue | ||
{ | ||
use Dispatchable, Queueable; | ||
|
||
public static $ran = false; | ||
public static $usedQueue = null; | ||
public static $usedConnection = null; | ||
public static $value = null; | ||
|
||
public function __construct($value) | ||
{ | ||
static::$value = $value; | ||
} | ||
|
||
public function handle() | ||
{ | ||
static::$ran = true; | ||
} | ||
|
||
public function replaceValue($value) | ||
{ | ||
static::$value = $value; | ||
} | ||
} |