1

Is this possible to avoid mocking in phpunit?

My concept is to: - write unit tests to test smaller parts - when it comes to do a integration/functional test then it's possible to inject a null object class using the dependency injection (so it's good to have everything interfaced). But integration tests could be separated from unit tests.

The reason why I don't like the mocking is that I see that its underused in every test, it's totally not readable. I was thinking about separation on unit testing and integration testing.

Could this in most cases be alternative to mocking, or is the mocking not replaceable at all? What's the best practice?

user2672165
  • 2,986
  • 19
  • 27

1 Answers1

0

Of course, you don't have to use mocks. You need fakes

A Fake avoids overspecifying a test for a very invasive contract, like the order of calls and precise parameters; a real implementation is more robust to changes in the contract.

This helps in focusing on the essence of your test (because you don't put long mocks' expectations in your tests). Also, it's possible to replace mocks at all.

Consider the example in this article.

Community
  • 1
  • 1
Piotr Dawidiuk
  • 2,961
  • 1
  • 24
  • 33