Level 1
You can rebind guard mock to ioc container before test is run (setUp method in PHPUnit) or you can use aspect mock.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How do I mock Guard in L5 testing?
use Illuminate\Contracts\Auth\Guard;
class SubscriptionController extends WebhookController {
protected $auth;
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
public function postCancel()
{
$this->auth->user()->subscription()->cancel();
}
}
How to I mock this so in my test I dont actually hit the stripe API?
Please or to participate in this conversation.