|
3 | 3 | namespace Illuminate\Tests\Integration\Queue;
|
4 | 4 |
|
5 | 5 | use Illuminate\Bus\Batchable;
|
| 6 | +use Illuminate\Bus\PendingBatch; |
6 | 7 | use Illuminate\Bus\Queueable;
|
7 | 8 | use Illuminate\Contracts\Queue\ShouldQueue;
|
8 | 9 | use Illuminate\Foundation\Bus\Dispatchable;
|
| 10 | +use Illuminate\Foundation\Bus\PendingChain; |
9 | 11 | use Illuminate\Foundation\Testing\DatabaseMigrations;
|
10 | 12 | use Illuminate\Queue\InteractsWithQueue;
|
11 | 13 | use Illuminate\Support\Carbon;
|
@@ -387,6 +389,43 @@ public function testChainBatchFailureNotAllowed()
|
387 | 389 | $this->assertEquals(['c1', 'c2', 'b1', 'b3'], JobRunRecorder::$results);
|
388 | 390 | $this->assertEquals(['batch failed', 'chain failed'], JobRunRecorder::$failures);
|
389 | 391 | }
|
| 392 | + |
| 393 | + public function testChainConditionable() |
| 394 | + { |
| 395 | + $chain = Bus::chain([]) |
| 396 | + ->onConnection('sync1') |
| 397 | + ->when(true, function (PendingChain $chain) { |
| 398 | + $chain->onConnection('sync2'); |
| 399 | + }); |
| 400 | + |
| 401 | + $this->assertEquals('sync2', $chain->connection); |
| 402 | + |
| 403 | + $chain = Bus::chain([]) |
| 404 | + ->onConnection('sync1') |
| 405 | + ->when(false, function (PendingChain $chain) { |
| 406 | + $chain->onConnection('sync2'); |
| 407 | + }); |
| 408 | + |
| 409 | + $this->assertEquals('sync1', $chain->connection); |
| 410 | + } |
| 411 | + |
| 412 | + public function testBatchConditionable() |
| 413 | + { |
| 414 | + $batch = Bus::batch([]) |
| 415 | + ->onConnection('sync1') |
| 416 | + ->when(true, function (PendingBatch $batch) { |
| 417 | + $batch->onConnection('sync2'); |
| 418 | + }); |
| 419 | + |
| 420 | + $this->assertEquals('sync2', $batch->connection()); |
| 421 | + $batch = Bus::batch([]) |
| 422 | + ->onConnection('sync1') |
| 423 | + ->when(false, function (PendingBatch $batch) { |
| 424 | + $batch->onConnection('sync2'); |
| 425 | + }); |
| 426 | + |
| 427 | + $this->assertEquals('sync1', $batch->connection()); |
| 428 | + } |
390 | 429 | }
|
391 | 430 |
|
392 | 431 | class JobChainingTestFirstJob implements ShouldQueue
|
|
0 commit comments