Design how your objects talk to each other through mocking
summary
Argues that tests should assert inter-object messages not just end state, demonstrating five test doubles (dummy, stub, spy, mock, fake) with the Prophecy library and showing concrete refactor patterns: replace flags with a payment method interface, add adapters to keep drivers interchangeable, split messenger interfaces, and introduce a JobRepository interface to avoid mocking Doctrine. Shows a controller test with roughly ten collaborators and seven messages, then refactors to far fewer collaborators and clearer responsibilities.
AI-written summary · about
chapters (12)
- 0:00Introduction to mocking and design
- 3:22What is test-driven development
- 11:26Types of test doubles explained
- 19:10Design principles and mocking
- 20:14Example 1: Simplifying MVC controllers
- 25:13Example 2: Basket checkout refactor
- 29:08Example 3: Browser emulation issues
- 34:44Example 4: ATM screen interface segregation
- 36:30Example 5: Entity repository dependency inversion
- 40:26Best practices for mocking
- 42:51Recap and key takeaways
- 43:19Q&A on PHPUnit mocks
