PHPackages                             mnapoli/phpunit-easymock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. mnapoli/phpunit-easymock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

mnapoli/phpunit-easymock
========================

Helpers to build PHPUnit mocks

1.5.0(1y ago)3876.7k↑72.7%47MITPHPPHP &gt;=7.3

Since Nov 11Pushed 1y ago3 watchersCompare

[ Source](https://github.com/mnapoli/phpunit-easymock)[ Packagist](https://packagist.org/packages/mnapoli/phpunit-easymock)[ Docs](https://github.com/mnapoli/phpunit-easymock)[ GitHub Sponsors](https://github.com/mnapoli)[ RSS](/packages/mnapoli-phpunit-easymock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (17)Used By (7)

PHPUnit EasyMock
================

[](#phpunit-easymock)

Helpers to build PHPUnit mock objects easily.

[![Total Downloads](https://camo.githubusercontent.com/cf60c241e2a7b0cb8831d51c64eb9816c54b207c33c1d85b781b44fe249c2337/68747470733a2f2f706f7365722e707567782e6f72672f6d6e61706f6c692f706870756e69742d656173796d6f636b2f646f776e6c6f616473)](https://packagist.org/packages/mnapoli/phpunit-easymock)

Why?
----

[](#why)

This library is **not** a mocking library. It's just a few helpers to write the most common mocks more easily.

It doesn't reinvent anything and is not intended to cover every use case: only the most common ones.

Installation
------------

[](#installation)

```
$ composer require --dev mnapoli/phpunit-easymock
```

To be able to use EasyMock in your tests **you must include the trait in your class**:

```
class MyTest extends \PHPUnit\Framework\TestCase
{
    use \EasyMock\EasyMock;

    // ...
}
```

Usage
-----

[](#usage)

Here is what a very common PHPUnit mock looks like:

```
$mock = $this->createMock('My\Class');

$mock->expect($this->any())
    ->method('sayHello')
    ->willReturn('Hello');
```

Yuck!

Here is how to write it with EasyMock:

```
$mock = $this->easyMock('My\Class', [
    'sayHello' => 'Hello',
]);
```

What if you want to assert that the method is called once (i.e. `$mock->expect($this->once())`)? Use `spy()` instead:

```
$mock = $this->easySpy('My\Class', [
    'sayHello' => 'Hello',
]);
```

### Features

[](#features)

You can mock methods so that they return values:

```
$mock = $this->easyMock('My\Class', [
    'sayHello' => 'Hello',
]);
```

Or so that they use a callback:

```
$mock = $this->easyMock('My\Class', [
    'sayHello' => function ($name) {
        return 'Hello ' . $name;
    },
]);
```

You can also have methods throw exceptions by providing an `Exception` instance:

```
$mock = $this->easyMock('My\Class', [
    'sayHello' => new \RuntimeException('Whoops'),
]);
```

It is possible to call the `mock()` method again on an existing mock:

```
$mock = $this->easyMock('My\Class');

$mock = $this->easyMock($mock, [
    'sayHello' => 'Hello',
]);
```

### What if?

[](#what-if)

If you want to use assertions or other PHPUnit features, just do it:

```
$mock = $this->easyMock('My\Class', [
    'sayHello' => 'hello',
]);

$mock->expects($this->once())
    ->method('sayGoodbye')
    ->willReturn('Goodbye');
```

Mocks are plain PHPUnit mocks, nothing special here.

Contributing
------------

[](#contributing)

See the [CONTRIBUTING](CONTRIBUTING.md) file.

License
-------

[](#license)

Released under the [MIT license](LICENSE).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 72.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~245 days

Recently: every ~539 days

Total

16

Last Release

524d ago

Major Versions

0.2.3 → 1.0.02017-11-11

PHP version history (7 changes)0.1.0PHP &gt;=5.3.0

0.2.0PHP &gt;=5.4.0

0.2.1PHP ~5.4|~7.0

1.0.0PHP ~7.0

1.2.0PHP ^7.2

1.3.0PHP ^7.3

1.4.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/329a6111724074f5388e95dd41a03ccf3c43f4bfe1ecf27c94c9efc6f7823228?d=identicon)[mnapoli](/maintainers/mnapoli)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (31 commits)")[![mimmi20](https://avatars.githubusercontent.com/u/1120192?v=4)](https://github.com/mimmi20 "mimmi20 (5 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (3 commits)")[![jdreesen](https://avatars.githubusercontent.com/u/424602?v=4)](https://github.com/jdreesen "jdreesen (2 commits)")[![phpfui](https://avatars.githubusercontent.com/u/7434059?v=4)](https://github.com/phpfui "phpfui (1 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (1 commits)")

---

Tags

phpphpunitphpunit-extensionphpunit-mocktestsphpunitmock

### Embed Badge

![Health badge](/badges/mnapoli-phpunit-easymock/health.svg)

```
[![Health](https://phpackages.com/badges/mnapoli-phpunit-easymock/health.svg)](https://phpackages.com/packages/mnapoli-phpunit-easymock)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[blastcloud/guzzler

Supercharge your app or SDK with a testing library specifically for Guzzle.

272419.3k35](/packages/blastcloud-guzzler)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[donatj/mock-webserver

Simple mock web server for unit testing

1382.5M80](/packages/donatj-mock-webserver)[nunomaduro/mock-final-classes

Allows mocking of final methods and classes in PHP.

113854.3k23](/packages/nunomaduro-mock-final-classes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
