mockery->shouldReceive() passing when it shouldnt? mockery->shouldReceive() passing when it shouldnt? laravel laravel

mockery->shouldReceive() passing when it shouldnt?


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)


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.


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