logo
podcast Podcast
get help Get Unstuck

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

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!

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.