Do not mock what you do not own

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

Mocking third-party types you don't own (like framework HTTP request objects) leads to brittle, complex tests tightly coupled to implementation details. The solution is to define your own domain-specific interface wrapping the framework's generic type, then mock that owned interface instead. Using PHP and PHPUnit examples, the post demonstrates how wrapping a framework's HttpRequest in a custom SomeRequestInterface with explicit methods (getId, getAmount, getPrice) makes test doubles simpler, decouples tests from call order, and keeps production code independent of the framework's HTTP abstraction.

7m read timeFrom thephp.cc
Post cover image

Sort: