1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
namespace Illuminate\Tests\Integration\Queue;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Orchestra\Testbench\TestCase;
class JobDispatchingTest extends TestCase
{
protected function tearDown(): void
{
Job::$ran = false;
}
public function testJobCanUseCustomMethodsAfterDispatch()
{
Job::dispatch('test')->replaceValue('new-test');
$this->assertTrue(Job::$ran);
$this->assertSame('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;
}
}
|