File tree Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Illuminate \Support \Facades ;
4
4
5
+ use Illuminate \Bus \BatchRepository ;
5
6
use Illuminate \Contracts \Bus \Dispatcher as BusDispatcherContract ;
6
7
use Illuminate \Foundation \Bus \PendingChain ;
7
8
use Illuminate \Support \Testing \Fakes \BusFake ;
@@ -54,11 +55,12 @@ class Bus extends Facade
54
55
* Replace the bound instance with a fake.
55
56
*
56
57
* @param array|string $jobsToFake
58
+ * @param \Illuminate\Bus\BatchRepository|null $batchRepository
57
59
* @return \Illuminate\Support\Testing\Fakes\BusFake
58
60
*/
59
- public static function fake ($ jobsToFake = [])
61
+ public static function fake ($ jobsToFake = [], BatchRepository $ batchRepository = null )
60
62
{
61
- static ::swap ($ fake = new BusFake (static ::getFacadeRoot (), $ jobsToFake ));
63
+ static ::swap ($ fake = new BusFake (static ::getFacadeRoot (), $ jobsToFake, $ batchRepository ));
62
64
63
65
return $ fake ;
64
66
}
Original file line number Diff line number Diff line change 3
3
namespace Illuminate \Support \Testing \Fakes ;
4
4
5
5
use Closure ;
6
+ use Illuminate \Bus \BatchRepository ;
6
7
use Illuminate \Bus \PendingBatch ;
7
8
use Illuminate \Contracts \Bus \QueueingDispatcher ;
8
9
use Illuminate \Support \Arr ;
@@ -75,13 +76,14 @@ class BusFake implements QueueingDispatcher
75
76
*
76
77
* @param \Illuminate\Contracts\Bus\QueueingDispatcher $dispatcher
77
78
* @param array|string $jobsToFake
79
+ * @param \Illuminate\Bus\BatchRepository|null $batchRepository
78
80
* @return void
79
81
*/
80
- public function __construct (QueueingDispatcher $ dispatcher , $ jobsToFake = [])
82
+ public function __construct (QueueingDispatcher $ dispatcher , $ jobsToFake = [], BatchRepository $ batchRepository = null )
81
83
{
82
84
$ this ->dispatcher = $ dispatcher ;
83
85
$ this ->jobsToFake = Arr::wrap ($ jobsToFake );
84
- $ this ->batchRepository = new BatchRepositoryFake ;
86
+ $ this ->batchRepository = $ batchRepository ?: new BatchRepositoryFake ;
85
87
}
86
88
87
89
/**
Original file line number Diff line number Diff line change 5
5
use Illuminate \Bus \Batch ;
6
6
use Illuminate \Bus \Queueable ;
7
7
use Illuminate \Contracts \Bus \QueueingDispatcher ;
8
+ use Illuminate \Support \Testing \Fakes \BatchRepositoryFake ;
8
9
use Illuminate \Support \Testing \Fakes \BusFake ;
9
10
use Mockery as m ;
10
11
use PHPUnit \Framework \Constraint \ExceptionMessage ;
@@ -28,6 +29,20 @@ protected function tearDown(): void
28
29
m::close ();
29
30
}
30
31
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
+
31
46
public function testAssertDispatched ()
32
47
{
33
48
try {
You can’t perform that action at this time.
0 commit comments