Repository navigation
Rule 2 Test behaviours not layouts
Part one: wiring. Tests say what the system does, in sentences a person could check. They do not test how the code is arranged.
The short form of every rule is in BUILD_PHILOSOPHY.md, which is the version that
counts. This page is the long form: why, where it shows today, and when not to use it.
A test that checks structure (a private method was called, a class has a property) breaks every time the code is tidied, while the behaviour stays correct. People then stop trusting the tests. A test that checks behaviour only fails when the behaviour is wrong, so a red test always means something.
-
tests/Unit/Http/SignInTest.phpdrives the control panel like a browser (tests/Fakes/Browser.php): welcome link, password, two-factor, dashboard, sign out, sign in again. It checks what a person would see, not which classes ran. - Test names read as sentences: "it refuses a code that was already used", "it stops guessing: after five wrong passwords even the right one waits".
- Fakes replace the outside world:
tests/Fakes/FakeHttpClient.phpinstead of GitHub,tests/Fakes/SteppingClock.phpinstead of the real time.
Some things only have a shape, not a behaviour: a template's HTML, a generated file. Test the one part that matters (the field is there, no inline styles) rather than the whole page.
Behaviour, fake, quality gates. See Glossary.
PHP 8.5 OOP Mastery, Rule 2 in its course philosophy, taught in module 5, testing and TDD. Course page.