CheckOps home

Tools directory

M

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.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

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

  1. Fluent expectations: shouldReceive()->once()->with()->andReturn().
  2. Spies and partial mocks: Verify after the fact or mock selected methods.
  3. Argument matchers: Flexible matching of call arguments.
  4. PHPUnit integration: Automatic expectation verification.

Pros

  1. Free to use: Open source under the BSD-3-Clause licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 18 October 2026.
  3. Community: About 10,700 GitHub stars.

Cons

  1. Overlap with PHPUnit mocks: Two mocking styles in one codebase can confuse teams.
  2. Alias and overload mocks: Powerful but can leak between tests if misused.
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.

  1. PHP and Laravel developers wanting readable mocks.
  2. 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.