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

[5.8] Return fake objects from facades #27680

Merged
merged 2 commits into from
Feb 27, 2019
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
6 changes: 4 additions & 2 deletions src/Illuminate/Support/Facades/Bus.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class Bus extends Facade
/**
* Replace the bound instance with a fake.
*
* @return void
* @return \Illuminate\Support\Testing\Fakes\BusFake
*/
public static function fake()
{
static::swap(new BusFake);
static::swap($fake = new BusFake);

return $fake;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Support/Facades/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class Event extends Facade
* Replace the bound instance with a fake.
*
* @param array|string $eventsToFake
* @return void
* @return \Illuminate\Support\Testing\Fakes\EventFake
*/
public static function fake($eventsToFake = [])
{
static::swap($fake = new EventFake(static::getFacadeRoot(), $eventsToFake));

Model::setEventDispatcher($fake);

return $fake;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Support/Facades/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ class Mail extends Facade
/**
* Replace the bound instance with a fake.
*
* @return void
* @return \Illuminate\Support\Testing\Fakes\MailFake
*/
public static function fake()
{
static::swap(new MailFake);
static::swap($fake = new MailFake);

return $fake;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Support/Facades/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class Queue extends Facade
/**
* Replace the bound instance with a fake.
*
* @return void
* @return \Illuminate\Support\Testing\Fakes\QueueFake
*/
public static function fake()
{
static::swap(new QueueFake(static::getFacadeApplication()));
static::swap($fake = new QueueFake(static::getFacadeApplication()));

return $fake;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/Illuminate/Support/Facades/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Storage extends Facade
*
* @param string|null $disk
*
* @return void
* @return \Illuminate\Filesystem\Filesystem
*/
public static function fake($disk = null)
{
Expand All @@ -26,22 +26,26 @@ public static function fake($disk = null)
$root = storage_path('framework/testing/disks/'.$disk)
);

static::set($disk, self::createLocalDriver(['root' => $root]));
static::set($disk, $fake = self::createLocalDriver(['root' => $root]));

return $fake;
}

/**
* Replace the given disk with a persistent local testing disk.
*
* @param string|null $disk
* @return void
* @return \Illuminate\Filesystem\Filesystem
*/
public static function persistentFake($disk = null)
{
$disk = $disk ?: self::$app['config']->get('filesystems.default');

static::set($disk, self::createLocalDriver([
static::set($disk, $fake = self::createLocalDriver([
'root' => storage_path('framework/testing/disks/'.$disk),
]));

return $fake;
}

/**
Expand Down