Skip to content

Commit 03c9ffa

Browse files
authored
Fake fixes (#46257)
* facade fake fix * make property public * change variable
1 parent 2f8a22c commit 03c9ffa

File tree

9 files changed

+32
-26
lines changed

9 files changed

+32
-26
lines changed

src/Illuminate/Support/Facades/Bus.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ class Bus extends Facade
6060
*/
6161
public static function fake($jobsToFake = [], BatchRepository $batchRepository = null)
6262
{
63-
return tap(new BusFake(static::getFacadeRoot(), $jobsToFake, $batchRepository), function ($fake) {
64-
if (! static::isFake()) {
65-
static::swap($fake);
66-
}
63+
$actualDispatcher = static::isFake()
64+
? static::getFacadeRoot()->dispatcher
65+
: static::getFacadeRoot();
66+
67+
return tap(new BusFake($actualDispatcher, $jobsToFake, $batchRepository), function ($fake) {
68+
static::swap($fake);
6769
});
6870
}
6971

src/Illuminate/Support/Facades/Event.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ class Event extends Facade
4747
*/
4848
public static function fake($eventsToFake = [])
4949
{
50-
return tap(new EventFake(static::getFacadeRoot(), $eventsToFake), function ($fake) {
51-
if (! static::isFake()) {
52-
static::swap($fake);
50+
$actualDispatcher = static::isFake()
51+
? static::getFacadeRoot()->dispatcher
52+
: static::getFacadeRoot();
5353

54-
Model::setEventDispatcher($fake);
55-
Cache::refreshEventDispatcher();
56-
}
54+
return tap(new EventFake($actualDispatcher, $eventsToFake), function ($fake) {
55+
static::swap($fake);
56+
57+
Model::setEventDispatcher($fake);
58+
Cache::refreshEventDispatcher();
5759
});
5860
}
5961

src/Illuminate/Support/Facades/Mail.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ class Mail extends Facade
6565
*/
6666
public static function fake()
6767
{
68-
return tap(new MailFake(static::getFacadeRoot()), function ($fake) {
69-
if (! static::isFake()) {
70-
static::swap($fake);
71-
}
68+
$actualMailManager = static::isFake()
69+
? static::getFacadeRoot()->manager
70+
: static::getFacadeRoot();
71+
72+
return tap(new MailFake($actualMailManager), function ($fake) {
73+
static::swap($fake);
7274
});
7375
}
7476

src/Illuminate/Support/Facades/Notification.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ class Notification extends Facade
4949
*/
5050
public static function fake()
5151
{
52-
return tap(new NotificationFake(), function ($fake) {
53-
if (! static::isFake()) {
54-
static::swap($fake);
55-
}
52+
return tap(new NotificationFake, function ($fake) {
53+
static::swap($fake);
5654
});
5755
}
5856

src/Illuminate/Support/Facades/Queue.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ public static function popUsing($workerName, $callback)
7676
*/
7777
public static function fake($jobsToFake = [])
7878
{
79-
return tap(new QueueFake(static::getFacadeApplication(), $jobsToFake, static::getFacadeRoot()), function ($fake) {
80-
if (! static::isFake()) {
81-
static::swap($fake);
82-
}
79+
$actualQueueManager = static::isFake()
80+
? static::getFacadeRoot()->queue
81+
: static::getFacadeRoot();
82+
83+
return tap(new QueueFake(static::getFacadeApplication(), $jobsToFake, $actualQueueManager), function ($fake) {
84+
static::swap($fake);
8385
});
8486
}
8587

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BusFake implements Fake, QueueingDispatcher
2020
*
2121
* @var \Illuminate\Contracts\Bus\QueueingDispatcher
2222
*/
23-
protected $dispatcher;
23+
public $dispatcher;
2424

2525
/**
2626
* The job types that should be intercepted instead of dispatched.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EventFake implements Dispatcher, Fake
2020
*
2121
* @var \Illuminate\Contracts\Events\Dispatcher
2222
*/
23-
protected $dispatcher;
23+
public $dispatcher;
2424

2525
/**
2626
* The event types that should be intercepted instead of dispatched.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MailFake implements Factory, Fake, Mailer, MailQueue
2222
*
2323
* @var MailManager
2424
*/
25-
protected $manager;
25+
public $manager;
2626

2727
/**
2828
* The mailer currently being used to send a message.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class QueueFake extends QueueManager implements Fake, Queue
2020
*
2121
* @var \Illuminate\Contracts\Queue\Queue
2222
*/
23-
protected $queue;
23+
public $queue;
2424

2525
/**
2626
* The job types that should be intercepted instead of pushed to the queue.

0 commit comments

Comments
 (0)