When testing, Laravel’s Http::preventStrayRequests() ensures that every HTTP request in your tests is either explicitly faked. This prevents accidental real API calls during testing, ensuring your suite remains fast and controlled.
Http::preventStrayRequests();
Http::fake([
'example.dev/*' => Http::response(['data' => 'something']),
]);
// Throws an exception because no fake is defined for this request
$response = Http::get('https://notfaked.dev/resource');
|