mockery->shouldReceive() passing when it shouldnt?

不羁岁月 提交于 2019-12-05 11:21:05
Bram Gerritsen

You shouldn't overwrite the constructor of PHPUnit_Framework_TestCase, use setUp for initialization purposes. See also my answer on #15051271 and also #17504870

Mockery is by default a stubbing library, not a mocking one (which is confusing because of its name).

That means that ->shouldReceive(...) by default is "zero or more times". When using ->once(), you say it should be called zero or one time, but not more. This means it'll always pass.

When you want to assert that it is called once, you can use ->atLeast()->times(1) (one or more times) or ->times(1) (exactly one time)

Guillermo Mansilla

To complete Wounter's answer, you must call Mockery::close().

This static call cleans up the Mockery container used by the current test, and run any verification tasks needed for your expectations.

This answer helped me understand this concept.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!