"Testing with Doubles: Why, When, and How?"
summary
Demonstrates how PHPUnit dynamically builds createStub and createMock objects to replace interfaces or non‑final classes, configure behavior with willReturn / willThrowException, and set call expectations like once, never or exactly(n). Shows a concrete SellGood command processor test using a MarketSourcer stub and a handwritten spy for event writing, explains automatic minimal return‑value generation, warns that final/value objects can’t be doubled, and recommends adapters so as to not mock what you do not own.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 1:07Why test doubles matter
- 6:54Test doubles explained
- 13:02Test stubs in practice
- 18:21Mock objects deep dive
- 22:57PHPUnit API for doubles
- 27:11What can and cannot be doubled
- 36:43When to use each type
- 40:58Company and resources
- 42:13Q&A
related talks
36mMocks, Stubs, and Spies, Oh My!
30mMocks, Stubs, and Spies, Oh My
01h 00mPrinciples of Unit Testing
40mTest Doubles are Not To Be Mocked
42mMocks, Fakes, Stubs – Is There a Difference? Do You Still Need Them?
27mFake Your Test Away: How To Abuse Your Test Doubles
59mYour tests are mocking you
01h 00mStop mocking everything
