Mocking Dependencies in Unit Tests with Phake
summary
Claims Phake provides a clearer, more featureful mocking API than PHPUnit and removes common hassles around stubbing, verification and ordering. Examples show installing via composer install, creating mocks with Phake::mock(), stubbing returns and callbacks, verifying call order and counts, capturing complex arguments, and using PHPUnit constraints for flexible expectations. Caveats include PHP limits around private, static and final methods and a few rough edges in Phake itself, but verifications produce readable failure messages and the library is usable as demonstrated.
AI-written summary · about
chapters (17)
- 0:00Intro
- 2:25Mike Lively
- 6:34Example Class Under Test
- 7:26Test Doubles
- 12:13Example Test With Stubbing
- 13:57Stub Behaviors
- 15:08private Methods
- 19:56Stubbing static Method Calls
- 21:06final Methods
- 21:30Stubbing final Method Calls
- 22:09Magic Methods
- 29:38Verifying Identical Invocations
- 30:34Verifying No Interaction
- 34:50PHPUnit Constraints
- 35:55Wildcard Parameters
- 39:03PHPUnit: Mocking
- 42:36PHPUnit: Verifying Order
related talks
59mYour tests are mocking you
01h 00mStop mocking everything
52mPlease don’t mock me
16mMastering Mocking in Playwright: Simplify API Test Automation
01h 00mPrinciples of Unit Testing
01h 01m“Mocking Frameworks considered harmful”
39mIntro to Mocking: Why Unit Testing Doesn't Have To Be So Hard
31mBeyond the Mockery- Why We Should Embrace Testing Without Mocking Frameworks
