Tests by Design
Next date: (in German)
Book · PHPStan extension · Agent skills
The PHPUnit manual tells you what every method, attribute, and configuration setting does. This book tells you which of them to reach for, and why.
The manual says what PHPUnit can do. It rarely says why one option is better than another. That knowledge exists, but it is scattered across admonitions in the manual, across articles and conference presentations, and across the experience of teams that have maintained a test suite for a decade. The book collects it in one place.
Every recommendation is stated as a rule, followed by the reason behind it. The reason matters more than the rule: a rule you understand can be broken deliberately when the situation calls for it, a rule you merely follow cannot.
Where a topic is documented in the manual, the book links to it instead of repeating it. Five of its thirteen chapters have no counterpart in the manual at all: analysing tests statically, changing code that has tests, keeping the test suite fast, keeping up with PHPUnit, and using the agent skills.
In the book, every rule is a heading of its own. What each chapter comes down to:
Many of the rules can be checked by reading the code, before a single test runs. The extension reports where test code departs from them. The chapter tells you why that matters, and when departing from the rule is the right decision.
It is meant to be used together with phpstan/phpstan-phpunit and phpstan/phpstan-deprecation-rules, and the book shows how to adopt its rules on an existing test suite with a ratchet.
The skills state the same rules in the form a coding agent can act on, so that the tests written on your behalf follow them:
phpunit-testing when tests are written or reviewed
phpunit-upgrade for the migration to a new major version
phpunit-performance for a test suite that has become slow
AGENTS.md
Together with the configuration of PHPUnit, this makes three layers, and each of them takes work off the next. The configuration reports what only a test run can show. PHPStan reports what the code shows. The skills are left with what neither of them can decide: whether a test verifies one aspect, whether a test stub or a mock object is the right double, whether an order is part of a contract.
The skills leave to the extension what it can check, and they make sure that it is installed and loaded. They do not replace the chapters: an agent that follows a rule it cannot justify will apply it in the wrong situation.
“This is the definite ‘high-speed introduction to useful test-driven development’. It’s to the point, the examples are as short as possible, and every chapter clear as glass. The whole of it helps to reflect on how you’re using PHPUnit nowadays, and where you might want to rethink your habits and improve yourself, no matter how much work agents now do for you.”
“I have written a fair number of tests for a project I develop on the side, and both the book and the Skills for Claude have been a great help. Especially when you do not work with it every day and have not built up a routine yet, being able to look things up quickly is ideal. The explanations are clear, and so far no question has been left unanswered.”
If you take part in one of these courses, you receive the book together with the PHPStan extension and the agent skills.
Next date: (in German)
Next date: (in German)
Next date: (in German)
Next date: (in German)
The book cannot be ordered or pre-ordered yet. Until it is out, many of its topics are covered in the articles and presentations on this site.
Sebastian Bergmann is the creator of PHPUnit, the de facto standard for testing PHP code, and writes its manual. Since 2001 he has been helping teams build maintainable and well-tested software as a consultant and trainer, since 2009 as a co-founder of thePHP.cc.