Your tests are mocking you
summary
Argues that mocks deserve repair not exile and demonstrates concrete patterns: handcrafted stubs via anonymous classes, PHPUnit auto-mockers, Prophecy/Mockery, and a Doctrine implementation that bootstraps metadata and creates a schema to run contract tests against the real DB. Shows collaboration tests that replace repo calls with stubs/spies, extracts behavior into simpler collaborators, and converts fragile mocks into fakes verified by a single Doctrine entity manager contract. Uses dozens of GitHub examples to prove tests become readable and maintainable with collaboration tests.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 1:52Test doubles and why use them
- 5:28Behavior verification
- 11:53Testing app levels
- 16:56Design for testability
- 19:04Collaboration tests and mocks
- 23:21Test doubles: stubs, mocks, spies, fakes
- 31:28Mocking indirect output
- 36:04Matching contracts with doubles
- 43:55Mocking mistakes and anti-patterns
- 50:21When to avoid mocking
- 52:08Summary
related talks
01h 00mStop mocking everything
01h 00mPrinciples of Unit Testing
50mMocking Dependencies in Unit Tests with Phake
31mBeyond the Mockery- Why We Should Embrace Testing Without Mocking Frameworks
41mTesting that the code does what the code does
47m"Testing with Doubles: Why, When, and How?"
49mTesting for the Brave and True
25mFakes over Mocks: Shift your paradigm and identify monolithic code
