A PHP Mockery alternative
$repository = Double::for(BookRepository::class);$repository->expects('find')->with(123)->returns($book); $service = new CatalogService($repository);$service->lookup(123); $repository->received('recordView')->with($book);If you're looking for a Mockery alternative in PHP, it's Double. Double is a modern PHP test double library. Its syntax is familiar on purpose. It isn't trying to change how you test, only your experience when you do.
Mockery has been the de facto PHP mocking library for the last decade, so it's baked into a lot of projects. For a long time it was simply the only choice, which isn't the same as being the best one. Mockery has long-standing papercuts most developers eventually hit, from dense exceptions to nuanced methods. Double addresses those.
Failures you can read
This is the main reason Double exists. When a Mockery expectation fails, you get a mangled class name and not much else. Double's failure messages name the double, the call, and what was called instead, so the next step is usually obvious.
One verb per idea
Mockery has several ways to say the same thing, and a few ways to get it subtly wrong, like forgetting ->once(). Double has expects(), allows(), and received(). That's it.
Double also doesn't make you choose between a mock, a spy, or a partial before you start. It works that out from what you ask of it. The name comes from Martin Fowler's generic term, test double, for the same reason.
Small enough to contribute to
The internals are small and well-bounded. Adding a matcher or improving a failure message shouldn't mean reverse-engineering the whole library first, whether you're a human or an AI.
Other options
Mockery isn't the only alternative to consider. PHPUnit offers built-in mocks. Prophecy and Phake offer different APIs. Double sits closest to Mockery.
The Migrating from Mockery guide maps each Mockery method to its Double equivalent, including what happens to Mockery spies. You can also convert your tests automatically with Shift. For the longer argument, see How is Double better than Mockery?