From 3b8aa9cf461fcc1a71e0893a6c2b55f63960c1dd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Feb 2023 15:20:43 +0530 Subject: [PATCH 1/3] facade fake fix --- src/Illuminate/Support/Facades/Bus.php | 10 ++++++---- src/Illuminate/Support/Facades/Event.php | 14 ++++++++------ src/Illuminate/Support/Facades/Mail.php | 10 ++++++---- src/Illuminate/Support/Facades/Notification.php | 6 ++---- src/Illuminate/Support/Facades/Queue.php | 10 ++++++---- src/Illuminate/Support/Testing/Fakes/BusFake.php | 2 +- src/Illuminate/Support/Testing/Fakes/EventFake.php | 2 +- src/Illuminate/Support/Testing/Fakes/MailFake.php | 2 +- 8 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/Illuminate/Support/Facades/Bus.php b/src/Illuminate/Support/Facades/Bus.php index 09fd4491004f..90aefb3fcc7a 100644 --- a/src/Illuminate/Support/Facades/Bus.php +++ b/src/Illuminate/Support/Facades/Bus.php @@ -60,10 +60,12 @@ class Bus extends Facade */ public static function fake($jobsToFake = [], BatchRepository $batchRepository = null) { - return tap(new BusFake(static::getFacadeRoot(), $jobsToFake, $batchRepository), function ($fake) { - if (! static::isFake()) { - static::swap($fake); - } + $actualBus = static::isFake() + ? static::getFacadeRoot()->dispatcher + : static::getFacadeRoot(); + + return tap(new BusFake($actualBus, $jobsToFake, $batchRepository), function ($fake) { + static::swap($fake); }); } diff --git a/src/Illuminate/Support/Facades/Event.php b/src/Illuminate/Support/Facades/Event.php index 879792915bbc..b5d14f8fb9e4 100755 --- a/src/Illuminate/Support/Facades/Event.php +++ b/src/Illuminate/Support/Facades/Event.php @@ -47,13 +47,15 @@ class Event extends Facade */ public static function fake($eventsToFake = []) { - return tap(new EventFake(static::getFacadeRoot(), $eventsToFake), function ($fake) { - if (! static::isFake()) { - static::swap($fake); + $actualDispatcher = static::isFake() + ? static::getFacadeRoot()->dispatcher + : static::getFacadeRoot(); - Model::setEventDispatcher($fake); - Cache::refreshEventDispatcher(); - } + return tap(new EventFake($actualDispatcher, $eventsToFake), function ($fake) { + static::swap($fake); + + Model::setEventDispatcher($fake); + Cache::refreshEventDispatcher(); }); } diff --git a/src/Illuminate/Support/Facades/Mail.php b/src/Illuminate/Support/Facades/Mail.php index 9b17d364781a..014a3611e2ff 100755 --- a/src/Illuminate/Support/Facades/Mail.php +++ b/src/Illuminate/Support/Facades/Mail.php @@ -65,10 +65,12 @@ class Mail extends Facade */ public static function fake() { - return tap(new MailFake(static::getFacadeRoot()), function ($fake) { - if (! static::isFake()) { - static::swap($fake); - } + $actualMailManager = static::isFake() + ? static::getFacadeRoot()->manager + : static::getFacadeRoot(); + + return tap(new MailFake($actualMailManager), function ($fake) { + static::swap($fake); }); } diff --git a/src/Illuminate/Support/Facades/Notification.php b/src/Illuminate/Support/Facades/Notification.php index bc5154f245af..e82aa0529d65 100644 --- a/src/Illuminate/Support/Facades/Notification.php +++ b/src/Illuminate/Support/Facades/Notification.php @@ -49,10 +49,8 @@ class Notification extends Facade */ public static function fake() { - return tap(new NotificationFake(), function ($fake) { - if (! static::isFake()) { - static::swap($fake); - } + return tap(new NotificationFake, function ($fake) { + static::swap($fake); }); } diff --git a/src/Illuminate/Support/Facades/Queue.php b/src/Illuminate/Support/Facades/Queue.php index 657b5f7c1b19..45b97e7a18bc 100755 --- a/src/Illuminate/Support/Facades/Queue.php +++ b/src/Illuminate/Support/Facades/Queue.php @@ -76,10 +76,12 @@ public static function popUsing($workerName, $callback) */ public static function fake($jobsToFake = []) { - return tap(new QueueFake(static::getFacadeApplication(), $jobsToFake, static::getFacadeRoot()), function ($fake) { - if (! static::isFake()) { - static::swap($fake); - } + $actualQueueManager = static::isFake() + ? static::getFacadeRoot()->queue + : static::getFacadeRoot(); + + return tap(new QueueFake(static::getFacadeApplication(), $jobsToFake, $actualQueueManager), function ($fake) { + static::swap($fake); }); } diff --git a/src/Illuminate/Support/Testing/Fakes/BusFake.php b/src/Illuminate/Support/Testing/Fakes/BusFake.php index d920459ee4b8..55b143df8255 100644 --- a/src/Illuminate/Support/Testing/Fakes/BusFake.php +++ b/src/Illuminate/Support/Testing/Fakes/BusFake.php @@ -20,7 +20,7 @@ class BusFake implements Fake, QueueingDispatcher * * @var \Illuminate\Contracts\Bus\QueueingDispatcher */ - protected $dispatcher; + public $dispatcher; /** * The job types that should be intercepted instead of dispatched. diff --git a/src/Illuminate/Support/Testing/Fakes/EventFake.php b/src/Illuminate/Support/Testing/Fakes/EventFake.php index 26a40b907d79..385a5348f9c2 100644 --- a/src/Illuminate/Support/Testing/Fakes/EventFake.php +++ b/src/Illuminate/Support/Testing/Fakes/EventFake.php @@ -20,7 +20,7 @@ class EventFake implements Dispatcher, Fake * * @var \Illuminate\Contracts\Events\Dispatcher */ - protected $dispatcher; + public $dispatcher; /** * The event types that should be intercepted instead of dispatched. diff --git a/src/Illuminate/Support/Testing/Fakes/MailFake.php b/src/Illuminate/Support/Testing/Fakes/MailFake.php index b982d2229e9e..d47373ffae12 100644 --- a/src/Illuminate/Support/Testing/Fakes/MailFake.php +++ b/src/Illuminate/Support/Testing/Fakes/MailFake.php @@ -22,7 +22,7 @@ class MailFake implements Factory, Fake, Mailer, MailQueue * * @var MailManager */ - protected $manager; + public $manager; /** * The mailer currently being used to send a message. From 254df67687168593b27a9080e1baddd1e5844b33 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Feb 2023 15:21:17 +0530 Subject: [PATCH 2/3] make property public --- src/Illuminate/Support/Testing/Fakes/QueueFake.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Testing/Fakes/QueueFake.php b/src/Illuminate/Support/Testing/Fakes/QueueFake.php index fef069713408..7218644ba860 100644 --- a/src/Illuminate/Support/Testing/Fakes/QueueFake.php +++ b/src/Illuminate/Support/Testing/Fakes/QueueFake.php @@ -20,7 +20,7 @@ class QueueFake extends QueueManager implements Fake, Queue * * @var \Illuminate\Contracts\Queue\Queue */ - protected $queue; + public $queue; /** * The job types that should be intercepted instead of pushed to the queue. From a889b577fe10b737d1f1a2ec33fce9119ea1872e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Feb 2023 15:22:31 +0530 Subject: [PATCH 3/3] change variable --- src/Illuminate/Support/Facades/Bus.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/Facades/Bus.php b/src/Illuminate/Support/Facades/Bus.php index 90aefb3fcc7a..ab410edc95d2 100644 --- a/src/Illuminate/Support/Facades/Bus.php +++ b/src/Illuminate/Support/Facades/Bus.php @@ -60,11 +60,11 @@ class Bus extends Facade */ public static function fake($jobsToFake = [], BatchRepository $batchRepository = null) { - $actualBus = static::isFake() + $actualDispatcher = static::isFake() ? static::getFacadeRoot()->dispatcher : static::getFacadeRoot(); - return tap(new BusFake($actualBus, $jobsToFake, $batchRepository), function ($fake) { + return tap(new BusFake($actualDispatcher, $jobsToFake, $batchRepository), function ($fake) { static::swap($fake); }); }