Testing code that makes an HTTP call meant injecting a mock client, which means the code had to accept one — so the test shaped the design rather than the other way round.
Http::fake([
'pricing.internal/*' => Http::response(['cents' => 4900], 200),
'slow.example/*' => Http::response(null, 500),
]);
$this->post('/quote', ['sku' => 'FR-100'])->assertOk();
Http::assertSent(fn($request) =>
$request->url() === 'https://pricing.internal/quotes'
&& $request['sku'] === 'FR-100');
The assertion on the outgoing request is the half people skip, and without it the test passes when the wrong URL is called with the wrong body. Http::preventStrayRequests() arrives later and is worth emulating with a catch-all fake that throws — otherwise an unmatched URL silently returns an empty 200 and the test asserts nothing useful. A fake is per test and does not persist, which is correct and occasionally confusing in a test that boots the application twice.