Testing with(out) dependencies
Why distinguishing between test stubs and mock objects in PHPUnit significantly improves the quality and readability of tests.
Photo by Niels Luigjes
On and , I was at SymfonyOnline. There I gave the presentation “Testing with(out) dependencies”.
This presentation clarifies effective strategies for using PHPUnit's test doubles to write robust, maintainable unit tests, highlighting practical techniques and common pitfalls to avoid.
More informationI am Sebastian Bergmann. I started writing PHPUnit in 2000 and still maintain it. In the same year I gave my first talk at a PHP conference. As a co-founder of thePHP.cc, I help teams in training courses and through consulting and coaching with everything related to PHPUnit, with quality gates for working with LLM-based coding agents, and with supply chain security.
I helped start the PHP Foundation and serve on its board. I have also represented the interests of Open Source at the European Commission and am active in the Open Source working group of the German Informatics Society (Gesellschaft für Informatik).
Where you can meet me next is listed under events. The next dates of my training courses are in the training overview.
Why distinguishing between test stubs and mock objects in PHPUnit significantly improves the quality and readability of tests.
The any() matcher is deprecated. But migration is easier than you think – and leads to better tests.
I explain how PHPUnit 13's parameter set matchers finally solve the problem that made upgrading to PHPUnit 10 such a challenge.
Self-sabotaging mock objects? With PHPUnit 12.5, that's a thing of the past because the test runner now asks the right question: Do you really need a mock object, or would a test stub suffice?
Do you want your team to get better at testing? I can help with consulting, coaching, and training.