CheckOps
Mockery
Mockery is a BSD-3-Clause mock object framework for PHP with a fluent, readable expectation API, usable with PHPUnit, Pest and other frameworks, and bundled with Laravel's testing tools.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
Mockery is a simple yet flexible PHP mock object framework. It offers an alternative to PHPUnit’s built-in mock objects with a more natural, fluent API, and with about 10,700 GitHub stars it is one of the most popular PHP testing libraries; Laravel includes it as a development dependency for its testing helpers.
You create test doubles with Mockery::mock(PaymentGateway::class) and set expectations such as ->shouldReceive('charge')->once()->with(100)->andReturn('tx-1'). Mockery supports argument matchers, ordered expectations, partial mocks, spies (Mockery::spy() with shouldHaveReceived), mocking of final classes via overloading or aliasing in limited cases, demeter chains, and Mockery::close() to verify expectations, which PHPUnit integration (the MockeryPHPUnitIntegration trait) handles automatically. Version 1.6.15 was released on 19 August 2026.
The source code is at mockery/mockery on GitHub under the BSD-3-Clause licence, with about 10,700 stars; the most recent commit was on 18 October 2026.
Features
- Fluent expectations:
shouldReceive()->once()->with()->andReturn(). - Spies and partial mocks: Verify after the fact or mock selected methods.
- Argument matchers: Flexible matching of call arguments.
- PHPUnit integration: Automatic expectation verification.
Pros
- Free to use: Open source under the BSD-3-Clause licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 18 October 2026.
- Community: About 10,700 GitHub stars.
Cons
- Overlap with PHPUnit mocks: Two mocking styles in one codebase can confuse teams.
- Alias and overload mocks: Powerful but can leak between tests if misused.
Usage and Links (Example)
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
final class CheckoutTest extends TestCase
{
use MockeryPHPUnitIntegration;
public function testChargesCard(): void
{
$gateway = Mockery::mock(PaymentGateway::class);
$gateway->shouldReceive('charge')->once()->with(100)->andReturn('tx-1');
$checkout = new Checkout($gateway);
$this->assertSame('tx-1', $checkout->pay(100));
}
}
Resources:
Pricing
Mockery is free and open source under the BSD-3-Clause licence.
Recommended for?
- PHP and Laravel developers wanting readable mocks.
- Teams that prefer fluent expectations over PHPUnit’s mock builder.
Conclusion
Mockery is the most popular PHP mocking library, readable, flexible and deeply integrated into the Laravel ecosystem.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with Mockery side by side.
PPHPUnitPHPUnit is the BSD-3-Clause, programmer-oriented testing framework for PHP and an instance of the xUnit architecture, created by Sebastian Bergmann and distributed as a PHAR or via Composer.Compare with Mockery
PPestPest is an MIT-licensed PHP testing framework built on PHPUnit with an expressive, closure-based API; Pest 5 (PHP 8.4+, PHPUnit 13) adds the Tia engine, an agent plugin, evals, PHPStan and Rector support.Compare with Mockery
Pphpspecphpspec is an MIT-licensed specification-oriented BDD toolset for PHP that helps you design classes by writing specs first, with code generation for missing classes and methods.Compare with Mockery
CCodeceptionCodeception is an MIT-licensed full-stack PHP testing framework covering unit, functional, API and acceptance tests in one tool, with modules for WebDriver, REST, databases and frameworks such as Laravel and Symfony.Compare with Mockery
MMoqMoq is a popular MIT-licensed mocking library for .NET that uses lambda expressions to set up and verify mocks; stable v4.x is maintained on the v4 branch while the main branch hosts the upcoming v5.Compare with Mockery
MMockitoMockito is the MIT-licensed, most popular mocking framework for Java, used to create mocks, stubs and spies with a clean API; Mockito 5 uses the inline mock maker by default and requires Java 11.Compare with Mockery