logo

When better architecture makes testing slightly harder

Choosing correctness over convenience

Joel Clermont
Joel Clermont
2025-11-27

On a recent code review, Aaron suggested moving some logic from a Livewire component method into a model observer.

We don't use observers very often, but this was critical logic that should always run, regardless of how the model is created or updated.

Currently, we only create or update this model in this one component, but in the future someone might create or update the model elsewhere, bypassing that important business logic.

So he convinced me it was the right choice and I agreed to change it.

Then, in the process of refactoring it, I bumped into some annoying behavior in my tests. This extra logic getting fired in the observer was now something I had to think about each time I reached for the factory.

This made testing a little bit more tedious, and I started to reconsider if this change was actually worth it after all.

But after some thought, I settled down and realized that ease of testing ease is always secondary to code correctness and maintainability.

In many cases, good app architecture leads to easier testing, but it's not a universal truth.

So in this one instance where better architecture made testing slightly less convenient, the priority of well-architected code still wins out.

Here to help,

Joel

P.S. Would you like a set of Laravel experts to review your code and give suggestions where you can improve? Schedule a call to get started.

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.