A while ago, at I explained how we make sure tests don't reach the outside world.
Read the tip if you haven't seen it, but in short we override the relevant environment variables in our phpunit.xml
file to a nonsense value like do-not-use-this
.
There's a subtle, but powerful, benefit to using a fake, but human-readable, value like that.
When you see do-not-use-this
in your test output, it's a clear signal that something is wrong. It's a visual cue that you've made a mistake in your test setup.
Compare that to just overriding the value to an empty string. The external API call would still be blocked by an empty string, but it becomes completely invisible in your test output.
This little trick won't make a difference the vast majority of the time, but I can tell you from experience, that the one time it does help, it will save you a ton of time trying to debug a failing test.
Here to help,
Joel
P.S. Have you ever encountered a tricky testing issue? Share your experience in the Mastering Laravel community. We learn best when we learn together!