Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Dave Marshall:
Mockery Spies
Oct 09, 2014 @ 15:29:08

In his latest post Dave Marshall takes a look at a handy feature of the Mockery mocking tool (helpful for unit testing) and how to use them in your testing.

Spies have been on the cards for mockery for a long time and even after putting together an implementation in February, I kind of stalled out on making a decision on the public API. Fast forward a few months and I figured it was just time to ship it, so I went with the most mockery like API and merged it in. Mockery still doesn't have a 1.0 release, so I can always make changes before we go 1.0.

For those not familiar with the concept of "spies" in testing he includes a brief definition and some of the reasoning behind using them. The first is relatively simple: how they can reveal the intent of the test. They also allow for two other types of testing methods, "Arrange-Act-Assert" or "Given-When-Then" thinking patterns. He does mention, however, some of the problems with using spies over mocks (including that they're less precise, possibly leading to looser testing). He finishes up the post with a quick note about partial spies and how they can provide a nice compromise in your testing.

tagged: mockery unittest spies doubles mock compare feature

Link: http://davedevelopment.co.uk/2014/10/09/mockery-spies.html


Trending Topics: