-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.x] Add
getJob()
method to PendingDispatch
class + Introduced …
…tests (#53951) * Add `getJob()` method to `PendingDispatch` class + tests * Fix styling * Update PendingDispatch.php --------- Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
fd07e20
commit 70607c5
Showing
2 changed files
with
127 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,117 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Bus; | ||
|
||
use Illuminate\Foundation\Bus\PendingDispatch; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use ReflectionClass; | ||
use stdClass; | ||
|
||
class PendingDispatchWithoutDestructor extends PendingDispatch | ||
{ | ||
public function __destruct() | ||
{ | ||
// Prevent the job from being dispatched | ||
} | ||
} | ||
|
||
class BusPendingDispatchTest extends TestCase | ||
{ | ||
protected $job; | ||
|
||
/** | ||
* @var PendingDispatchWithoutDestructor | ||
*/ | ||
protected $pendingDispatch; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->job = m::mock(stdClass::class); | ||
$this->pendingDispatch = new PendingDispatchWithoutDestructor($this->job); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
m::close(); | ||
} | ||
|
||
public function testOnConnection() | ||
{ | ||
$this->job->shouldReceive('onConnection')->once()->with('test-connection'); | ||
$this->pendingDispatch->onConnection('test-connection'); | ||
} | ||
|
||
public function testOnQueue() | ||
{ | ||
$this->job->shouldReceive('onQueue')->once()->with('test-queue'); | ||
$this->pendingDispatch->onQueue('test-queue'); | ||
} | ||
|
||
public function testAllOnConnection() | ||
{ | ||
$this->job->shouldReceive('allOnConnection')->once()->with('test-connection'); | ||
$this->pendingDispatch->allOnConnection('test-connection'); | ||
} | ||
|
||
public function testAllOnQueue() | ||
{ | ||
$this->job->shouldReceive('allOnQueue')->once()->with('test-queue'); | ||
$this->pendingDispatch->allOnQueue('test-queue'); | ||
} | ||
|
||
public function testDelay() | ||
{ | ||
$this->job->shouldReceive('delay')->once()->with(60); | ||
$this->pendingDispatch->delay(60); | ||
} | ||
|
||
public function testWithoutDelay() | ||
{ | ||
$this->job->shouldReceive('withoutDelay')->once(); | ||
$this->pendingDispatch->withoutDelay(); | ||
} | ||
|
||
public function testAfterCommit() | ||
{ | ||
$this->job->shouldReceive('afterCommit')->once(); | ||
$this->pendingDispatch->afterCommit(); | ||
} | ||
|
||
public function testBeforeCommit() | ||
{ | ||
$this->job->shouldReceive('beforeCommit')->once(); | ||
$this->pendingDispatch->beforeCommit(); | ||
} | ||
|
||
public function testChain() | ||
{ | ||
$chain = [new stdClass]; | ||
$this->job->shouldReceive('chain')->once()->with($chain); | ||
$this->pendingDispatch->chain($chain); | ||
} | ||
|
||
public function testAfterResponse() | ||
{ | ||
$this->pendingDispatch->afterResponse(); | ||
$this->assertTrue( | ||
(new ReflectionClass($this->pendingDispatch))->getProperty('afterResponse')->getValue($this->pendingDispatch) | ||
); | ||
} | ||
|
||
public function testGetJob() | ||
{ | ||
$this->assertSame($this->job, $this->pendingDispatch->getJob()); | ||
} | ||
|
||
public function testDynamicallyProxyMethods() | ||
{ | ||
$newJob = m::mock(stdClass::class); | ||
$this->job->shouldReceive('appendToChain')->once()->with($newJob); | ||
$this->pendingDispatch->appendToChain($newJob); | ||
} | ||
} |