Http::fake only works if you're actually using the Http class in your code.It doesn't catch all outgoing HTTP calls in your application.
$response = Http::post('my-url');
If you do this, fake should work correctly here.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I am trying to test some external API calls with a fake call using the Http client that Laravel provides out of the box, but for some reason I am not getting the fake version that I have specified, instead it just proceeds to hit the API for some reason.
Here's an example code in my test:
$http = app(Factory::class);
$http->fake(function ($request) use($http) {
return $http->response(['Status' => 0], Response::HTTP_OK);
});
After this I do something like:
$response = $this->postJson('my-url', $attributes);
and I get the original response from the external API instead of the fake one that i specified in my test.
Anyone have any ideas what am I missing?
Http::fake only works if you're actually using the Http class in your code.It doesn't catch all outgoing HTTP calls in your application.
$response = Http::post('my-url');
If you do this, fake should work correctly here.
Please or to participate in this conversation.