Catch unfaked Http requests
I am working on application that rely on many external apis.
All the tests should be based on mocks by facade Http and method Http::fake()
Is it possible to throw an exception if any request to external service is not covered by Http::fake()?
I know how to resolve it by global middleware. But I am looking for any resolution in TestCase::setUp()
Yes, it is possible to prevent these HTTP calls using the method preventStrayRequests which has been added since Laravel 9.
Http::preventStrayRequests();
If a requested URL is not faked, the test will throw an exception.
RuntimeException: Attempted request to [laracasts.com] without a matching fake.
Thank you. It it’s what I looking for.
Please or to participate in this conversation.