Using in-memory fakes to replace secondary adapters is very powerful, it allows to have tests that run under a second (As I presented in this article : Test All your Business Logic in less than 1 second ). It also comes with some tradeoffs :
- In-memory fakes can be hard to maintain
- In-memory fakes and real implementations behaviors can diverge
Mostly use in integration tests (Ex : php-vcr), this technique can be also use to record and replay to fake the behavior of the secondary adapters (Repository, gateway, etc).
I created a helper class RecordReplay able to create proxy around a secondary adapter. Since the proxy implements the same interface it will be able to record every call to the secondary adapter.