Skip to content

Commit f9912c7

Browse files
committed
Merge branch 'mihaliak/9.x' into 9.x
2 parents 28d07f0 + 3cb4a8f commit f9912c7

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/Illuminate/Support/Facades/Bus.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Support\Facades;
44

5+
use Illuminate\Bus\BatchRepository;
56
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract;
67
use Illuminate\Foundation\Bus\PendingChain;
78
use Illuminate\Support\Testing\Fakes\BusFake;
@@ -54,11 +55,12 @@ class Bus extends Facade
5455
* Replace the bound instance with a fake.
5556
*
5657
* @param array|string $jobsToFake
58+
* @param \Illuminate\Bus\BatchRepository|null $batchRepository
5759
* @return \Illuminate\Support\Testing\Fakes\BusFake
5860
*/
59-
public static function fake($jobsToFake = [])
61+
public static function fake($jobsToFake = [], BatchRepository $batchRepository = null)
6062
{
61-
static::swap($fake = new BusFake(static::getFacadeRoot(), $jobsToFake));
63+
static::swap($fake = new BusFake(static::getFacadeRoot(), $jobsToFake, $batchRepository));
6264

6365
return $fake;
6466
}

src/Illuminate/Support/Testing/Fakes/BusFake.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Support\Testing\Fakes;
44

55
use Closure;
6+
use Illuminate\Bus\BatchRepository;
67
use Illuminate\Bus\PendingBatch;
78
use Illuminate\Contracts\Bus\QueueingDispatcher;
89
use Illuminate\Support\Arr;
@@ -75,13 +76,14 @@ class BusFake implements QueueingDispatcher
7576
*
7677
* @param \Illuminate\Contracts\Bus\QueueingDispatcher $dispatcher
7778
* @param array|string $jobsToFake
79+
* @param \Illuminate\Bus\BatchRepository|null $batchRepository
7880
* @return void
7981
*/
80-
public function __construct(QueueingDispatcher $dispatcher, $jobsToFake = [])
82+
public function __construct(QueueingDispatcher $dispatcher, $jobsToFake = [], BatchRepository $batchRepository = null)
8183
{
8284
$this->dispatcher = $dispatcher;
8385
$this->jobsToFake = Arr::wrap($jobsToFake);
84-
$this->batchRepository = new BatchRepositoryFake;
86+
$this->batchRepository = $batchRepository ?: new BatchRepositoryFake;
8587
}
8688

8789
/**

tests/Support/SupportTestingBusFakeTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Bus\Batch;
66
use Illuminate\Bus\Queueable;
77
use Illuminate\Contracts\Bus\QueueingDispatcher;
8+
use Illuminate\Support\Testing\Fakes\BatchRepositoryFake;
89
use Illuminate\Support\Testing\Fakes\BusFake;
910
use Mockery as m;
1011
use PHPUnit\Framework\Constraint\ExceptionMessage;
@@ -28,6 +29,20 @@ protected function tearDown(): void
2829
m::close();
2930
}
3031

32+
public function testItUsesCustomBusRepository()
33+
{
34+
$busRepository = new BatchRepositoryFake;
35+
36+
$fake = new BusFake(m::mock(QueueingDispatcher::class), [], $busRepository);
37+
38+
$this->assertNull($fake->findBatch('non-existent-batch'));
39+
40+
$batch = $fake->batch([])->dispatch();
41+
42+
$this->assertSame($batch, $fake->findBatch($batch->id));
43+
$this->assertSame($batch, $busRepository->find($batch->id));
44+
}
45+
3146
public function testAssertDispatched()
3247
{
3348
try {

0 commit comments

Comments
 (0)