PHPackages                             ondrejmirtes/mocktainer - 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. ondrejmirtes/mocktainer

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

ondrejmirtes/mocktainer
=======================

Create objects of classes with mocked dependencies more easily!

0.8(7y ago)35903[2 PRs](https://github.com/ondrejmirtes/mocktainer/pulls)MITPHPPHP ^7.2

Since May 10Pushed 7y ago2 watchersCompare

[ Source](https://github.com/ondrejmirtes/mocktainer)[ Packagist](https://packagist.org/packages/ondrejmirtes/mocktainer)[ RSS](/packages/ondrejmirtes-mocktainer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (9)Used By (0)

Mocktainer
==========

[](#mocktainer)

[![Build Status](https://camo.githubusercontent.com/8964da29e048088872f0288c58b471d1e004b79b7fd2811831057a2fc07358f8/68747470733a2f2f7472617669732d63692e6f72672f6f6e6472656a6d69727465732f6d6f636b7461696e65722e737667)](https://travis-ci.org/ondrejmirtes/mocktainer)[![Coverage Status](https://camo.githubusercontent.com/ed164354d67f142fdd428f45cc5be221693b2913389dad10a889ab4418ec8b6e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6f6e6472656a6d69727465732f6d6f636b7461696e65722f62616467652e737667)](https://coveralls.io/r/ondrejmirtes/mocktainer)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4422d6f096af79e913e8b5043fff8b6a6e1314fbd698c3266852ea024e7a2490/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6e6472656a6d69727465732f6d6f636b7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ondrejmirtes/mocktainer/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/d969a6318a6bb9b993f5b2ceeb7e102426c1bcee9c66465211452e0354209e5d/68747470733a2f2f706f7365722e707567782e6f72672f6f6e6472656a6d69727465732f6d6f636b7461696e65722f762f737461626c65)](https://packagist.org/packages/ondrejmirtes/mocktainer)

Tired of passing mocked dependencies you don't care about to classes under test?

Is this code familiar to you?

```
$foo1 = $this->getMockBuilder(Foo1::class)
	->disableOriginalConstructor()
	->getMock();
$foo2 = $this->getMockBuilder(Foo2::class)
	->disableOriginalConstructor()
	->getMock();
$foo3 = $this->getMockBuilder(Foo3::class)
	->disableOriginalConstructor()
	->getMock();
$foo4 = $this->getMockBuilder(Foo4::class)
	->disableOriginalConstructor()
	->getMock();
$interestingDependency = $this->getMock(Foo5::class);
$interestingDependency->expects($this->once())
	->method('getAwesome')
	->getMock();

// public function __construct(Foo1 $foo1, Foo2 $foo2, Foo3 $foo3, Foo4 $foo4, Foo5 $foo5)
$bar = new Bar($foo1, $foo2, $foo3, $foo4, $interestingDependency);
```

With **Mocktainer**, you can reduce the above code to this:

```
$interestingDependency = $this->getMock(Foo5::class);
$interestingDependency->expects($this->once())
	->method('getAwesome')
	->getMock();

$bar = $this->getMocktainer()->create(Bar::class, ['foo5' => $interestingDependency]);
```

Other mockable constructor arguments will be mocked using `MockBuilder` and `disableOriginalConstructor()`.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.8% 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 ~195 days

Recently: every ~286 days

Total

8

Last Release

2661d ago

PHP version history (5 changes)0.1PHP ~5.6

0.4PHP ^5.6|^7.0

0.5PHP ^7.0

0.7PHP ^7.1

0.8PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/258cf2d2422f7e9ac5f7e1bb7a331f3fb717a11e51de7a3de2d6025507bd63cf?d=identicon)[ondrejmirtes](/maintainers/ondrejmirtes)

---

Top Contributors

[![ondrejmirtes](https://avatars.githubusercontent.com/u/104888?v=4)](https://github.com/ondrejmirtes "ondrejmirtes (24 commits)")[![kukulich](https://avatars.githubusercontent.com/u/260445?v=4)](https://github.com/kukulich "kukulich (3 commits)")[![janlanger](https://avatars.githubusercontent.com/u/415695?v=4)](https://github.com/janlanger "janlanger (2 commits)")

---

Tags

phpphp7phpunitunit-testing

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ondrejmirtes-mocktainer/health.svg)

```
[![Health](https://phpackages.com/badges/ondrejmirtes-mocktainer/health.svg)](https://phpackages.com/packages/ondrejmirtes-mocktainer)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M775](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)

PHPackages © 2026

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