Black Friday: the Laravel testing course is $149 instead of $249, through Dec 7. See the course →
logo

Why we use obviously fake values in the test config

A small improvement with a potentially huge benefit

Joel Clermont
Joel Clermont
2025-02-11

From our daily Laravel tips email. Get the next one in your inbox.

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!

Want a tip like this in your inbox every weekday?

Each one takes less than 2 minutes to read. Join 4,000+ Laravel developers who already get them.

email
No spam. Only real-world advice.
Toss a coin in the jar if you found this helpful.