Skip to content

Commit

Permalink
Fake fixes (#46257)
Browse files Browse the repository at this point in the history
* facade fake fix

* make property public

* change variable
  • Loading branch information
taylorotwell authored Feb 24, 2023
1 parent 2f8a22c commit 03c9ffa
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 26 deletions.
10 changes: 6 additions & 4 deletions src/Illuminate/Support/Facades/Bus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
$actualDispatcher = static::isFake()
? static::getFacadeRoot()->dispatcher
: static::getFacadeRoot();

return tap(new BusFake($actualDispatcher, $jobsToFake, $batchRepository), function ($fake) {
static::swap($fake);
});
}

Expand Down
14 changes: 8 additions & 6 deletions src/Illuminate/Support/Facades/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand Down
10 changes: 6 additions & 4 deletions src/Illuminate/Support/Facades/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
6 changes: 2 additions & 4 deletions src/Illuminate/Support/Facades/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
10 changes: 6 additions & 4 deletions src/Illuminate/Support/Facades/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Testing/Fakes/BusFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Testing/Fakes/EventFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Testing/Fakes/MailFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Testing/Fakes/QueueFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 03c9ffa

Please sign in to comment.