Skip to content
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
6 changes: 5 additions & 1 deletion src/Illuminate/Queue/CallQueuedClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ public function failed($e)
*/
public function displayName()
{
$reflection = new ReflectionFunction($this->closure->getClosure());
$closure = $this->closure instanceof SerializableClosure
? $this->closure->getClosure()
: $this->closure;

$reflection = new ReflectionFunction($closure);

$prefix = is_null($this->name) ? '' : "{$this->name} - ";

Expand Down
62 changes: 62 additions & 0 deletions tests/Bus/BusBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@
use Illuminate\Bus\Batchable;
use Illuminate\Bus\BatchFactory;
use Illuminate\Bus\DatabaseBatchRepository;
use Illuminate\Bus\Dispatcher;
use Illuminate\Bus\PendingBatch;
use Illuminate\Bus\Queueable;
use Illuminate\Container\Container;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
use Illuminate\Contracts\Queue\Factory;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\PostgresConnection;
use Illuminate\Database\Query\Builder;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Foundation\Bus\PendingChain;
use Illuminate\Queue\CallQueuedClosure;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Queue;
use Mockery as m;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
Expand All @@ -38,6 +44,35 @@ protected function setUp(): void
$db->bootEloquent();
$db->setAsGlobal();

if (! Facade::getFacadeApplication()) {
$container = new Container;
Facade::setFacadeApplication($container);

$queue = m::mock(Factory::class);
$container->instance(Factory::class, $queue);
$container->alias(Factory::class, 'queue');

$dispatcher = m::mock(Dispatcher::class, [$container]);

$dispatcher->shouldReceive('batch')->zeroOrMoreTimes()->andReturnUsing(function ($jobs) {
$pendingBatch = m::mock(PendingBatch::class);
$pendingBatch->shouldReceive('name')->andReturnSelf();
$pendingBatch->shouldReceive('dispatch')->zeroOrMoreTimes()->andReturn(m::mock(Batch::class));

return $pendingBatch;
})->byDefault();

$dispatcher->shouldReceive('chain')->zeroOrMoreTimes()->andReturnUsing(function ($jobs) {
$pendingChain = m::mock(PendingChain::class, [$jobs, \stdClass::class]);
$pendingChain->shouldReceive('dispatch')->zeroOrMoreTimes()->andReturn(m::mock(Batch::class));

return $pendingChain;
})->byDefault();

$container->instance(BusDispatcher::class, $dispatcher);
$container->alias(BusDispatcher::class, 'bus');
}

$this->createSchema();

$_SERVER['__finally.count'] = 0;
Expand Down Expand Up @@ -74,6 +109,10 @@ public function createSchema()
*/
protected function tearDown(): void
{
if (Facade::getFacadeApplication()) {
Facade::setFacadeApplication(null);
}

unset($_SERVER['__finally.batch'], $_SERVER['__progress.batch'], $_SERVER['__then.batch'], $_SERVER['__catch.batch'], $_SERVER['__catch.exception']);

$this->schema()->drop('job_batches');
Expand Down Expand Up @@ -456,6 +495,29 @@ public function test_chain_can_be_added_to_batch()
$this->assertInstanceOf(CarbonImmutable::class, $batch->createdAt);
}

public function test_chained_closure_after_multiple_batches_is_properly_dispatched()
{
Queue::fake();

$TestBatchJob = new class
{
use Batchable;

public function handle()
{
}
};

Bus::chain([
Bus::batch([$TestBatchJob])->name('Batch 1'),
Bus::batch([$TestBatchJob])->name('Batch 2'),
function () {
},
])->dispatch();

$this->assertTrue(true);
}

public function test_options_serialization_on_postgres()
{
$pendingBatch = (new PendingBatch(new Container, collect()))
Expand Down