Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add getJob() method to PendingDispatch class + Introduced tests #53951

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/Bus/PendingDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ protected function shouldDispatch()
->acquire($this->job);
}

/**
* Get the underlying job instance.
*
* @var mixed
*/
public function getJob()
{
return $this->job;
}

/**
* Dynamically proxy methods to the underlying job.
*
Expand Down
117 changes: 117 additions & 0 deletions tests/Bus/BusPendingDispatchTest.php
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);
}
}