diff --git a/src/Illuminate/Bus/ChainedBatch.php b/src/Illuminate/Bus/ChainedBatch.php index d88aa0e7377e..431d3cfb120c 100644 --- a/src/Illuminate/Bus/ChainedBatch.php +++ b/src/Illuminate/Bus/ChainedBatch.php @@ -46,6 +46,9 @@ public function __construct(PendingBatch $batch) $this->name = $batch->name; $this->options = $batch->options; + + $this->queue = $batch->queue(); + $this->connection = $batch->connection(); } /** diff --git a/tests/Integration/Queue/JobChainingTest.php b/tests/Integration/Queue/JobChainingTest.php index 493abbec7609..b0f6dcde7764 100644 --- a/tests/Integration/Queue/JobChainingTest.php +++ b/tests/Integration/Queue/JobChainingTest.php @@ -396,6 +396,26 @@ public function testBatchCanBeAddedToChain() $this->assertEquals(['c1', 'c2', 'b1', 'b2', 'b3', 'b4', 'c3'], JobRunRecorder::$results); } + public function testBatchInChainUsesCorrectQueue() + { + $otherQueue = $this->getQueueDriver() === 'redis' ? '{other}' : 'other'; + Bus::chain([ + (new JobChainingNamedTestJob('c1'))->onQueue($otherQueue), + (new JobChainingNamedTestJob('c2'))->onQueue($otherQueue), + Bus::batch([ + new JobChainingTestBatchedJob('b1'), + new JobChainingTestBatchedJob('b2'), + new JobChainingTestBatchedJob('b3'), + new JobChainingTestBatchedJob('b4'), + ])->onQueue($otherQueue), + (new JobChainingNamedTestJob('c3'))->onQueue($otherQueue), + ])->dispatch(); + + $this->runQueueWorkerCommand(['--queue' => $otherQueue, '--stop-when-empty' => true]); + + $this->assertEquals(['c1', 'c2', 'b1', 'b2', 'b3', 'b4', 'c3'], JobRunRecorder::$results); + } + public function testDynamicBatchCanBeAddedToChain() { Bus::chain([