Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fake fixes #46257

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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