You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a fake facade in a test, in certain instances the underlying logic may not be equivalent to your main application logic for the real thing. For instance, there could be notification handler logic containing additional checks whether to send a notification or not (e.g. user opt out). In this case it would be useful to be able to pass in and use a different fake other than the default.
// src/Illuminate/Support/Facades/NotificationFake.php/** * Replace the bound instance with a fake. * * @param \Illuminate\Support\Testing\Fakes\NotificationFake|null $fake * @return \Illuminate\Support\Testing\Fakes\NotificationFake */publicstaticfunctionfake($fake = null)
{
$fake ??= newNotificationFake;
static::swap($fake);
return$fake;
}
For example,
namespaceTests\Support;
useIlluminate\Support\Testing\Fakes\NotificationFake;
class MyNotificationFake extends NotificationFake
{
//
}
and call it with
use \Tests\Support\MyNotificationFake;
Notification::fake(newMyNotificationFake);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
When using a
fake
facade in a test, in certain instances the underlying logic may not be equivalent to your main application logic for the real thing. For instance, there could be notification handler logic containing additional checks whether to send a notification or not (e.g. user opt out). In this case it would be useful to be able to pass in and use a different fake other than the default.For example,
and call it with
Beta Was this translation helpful? Give feedback.
All reactions