
Double - a modern PHP mocking library focused on developer experience
After a few weeks of livestreaming the development process and dogfooding it in real projects, I'm excited to officially announce Double.
Double is a modern PHP mocking library focused on developer experience.
It stands on the shoulders of Mockery and RSpec. So there isn't much to learn. You get to enjoy a smoother DX.
A few things I wanted to improve:
- Less technical terminology
- Single, streamlined APIs
- Human failure messages
With Double, you create a double for your class and write expectations. Double handles the details.
use JMac\Testing\Double;
$repository = Double::for(BookRepository::class);
$repository->expects('find')->with(123)->returns($book);
$service = new CatalogService($repository);
$service->lookup(123);
$repository->received('recordView')->with($book);
When an expectation fails, you get a proper test failure (not an exception). Along with a human-friendly message showing what actually happened and, where appropriate, a suggestion.
I also generated modern documentation with AI and ui.sh, where you may learn more about Double.
I've wanted to build this for years. So I'm all-in on Double. I've already converted all of my own test suites from Mockery to Double. I created a free Double Converter to automate the process.
This is still v0. While I believe it's already beyond feature parity with Mockery, I want to continue to improve the developer experience.