phpunit avoid constructor arguments for mock

后端 未结 7 1088
有刺的猬
有刺的猬 2021-01-30 08:24

What is the way to avoid phpunit having to call the constructor for a mock object? Otherwise I would need a mock object as constructor argument, another one for that etc. The ap

7条回答
  •  被撕碎了的回忆
    2021-01-30 08:30

    PHPUnit is designed to call the constructor on mocked objects; to prevent this you should either:

    1. Inject a mock object as a dependency into the object you're having trouble mocking
    2. Create a test class that extends the class you're trying to call that doesn't call the parent constructor

提交回复
热议问题