PHPackages                             bigcommerce/mock-injector - 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. bigcommerce/mock-injector

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

bigcommerce/mock-injector
=========================

Auto-mocking injector for testing DI components

10.0.0(10mo ago)3188.4k↓21.4%7MITPHPPHP ^8.3

Since Jan 14Pushed 5mo ago110 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (28)Used By (0)

bigcommerce/mock-injector
=========================

[](#bigcommercemock-injector)

[![Build Status](https://camo.githubusercontent.com/0a2dff2ef2fe0e7836f9a5713a0db5863d22a6535b97237b2f18c615cc456fae/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f626967636f6d6d657263652f6d6f636b2d696e6a6563746f722f6261646765732f6275696c642e706e673f623d6d617374657226733d36623062643163306462373136626138356532633132613634643634306162316134643835333639)](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e6cd2d4a4ecc394a9701cfb2e02edceb19affc3f3abca57e32fbc5d87b3f02f3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f626967636f6d6d657263652f6d6f636b2d696e6a6563746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d617374657226733d63303831316664373662636233316639653733613062656238313134653564653334643966306361)](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/81acff8d22b9a66630b69c6b1a08d062afbbc90a3090cfcad5dacaee35bdff99/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f626967636f6d6d657263652f6d6f636b2d696e6a6563746f722f6261646765732f636f7665726167652e706e673f623d6d617374657226733d61353932653431343033393761393336373237636532386435393863613139303738616130613634)](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/?branch=master)

Auto-mocking test Dependency Injector component

Will automatically mock all injected dependencies of an object using the BigCommerce Injector. This allows objects to be refactored to have dependencies removed or new ones added without needing to rebuild all the mock definitions or modify many tests, making decoupled DI driven development much easier.

Mocks can be configured with expectations by calling getMock(CLASS\_NAME) on the TestInjector within your tests. This will return an ObjectProphecy object (a mock generated by Prophecy - the mocking library included in PHPUnit).

A single mock instance is created per Fully Qualified Class Name, so if the object you're testing takes two of the same typed parameter, the same mock will be passed to both (so ensure your expectations are set appropriately).

Construction Usage:

```
// All constructor dependencies resolved through mocking
$testObject = $testInjector->create(My\Test\Object::class);

// Parameter injection - will provide parameters either by type, name or position - otherwise resolve via mocking
$testObject = $testInjector->create(My\Test\Object::class, [
    "enabled" => true,              // Named
    7 => "fish",                    // Positional
    Logger::class => new Logger(),  // Type
]);

```

Invocation usage

```
// Call the method 'createUser' on an existing object
$result = $testInjector->invoke($instanceOfThing, "createUser");

// Parameter injection - will provide parameters either by type, name or position - otherwise resolve via mocking
$result = $testInjector->invoke($instanceOfThing, "createUser", [
    "enabled" => true,              // Named
    7 => "fish",                    // Positional
    Logger::class => new Logger(),  // Type
]);

```

For integration with your PHPUnit tests, see: [AutoMockingTest.php](src/AutoMockingTest.php)

(The MIT License) Copyright (C) 2015-2017 BigCommerce Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance62

Regular maintenance activity

Popularity38

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~118 days

Recently: every ~91 days

Total

27

Last Release

329d ago

Major Versions

v5.0.2 → 6.0.02023-05-25

6.0.0 → 7.0.02024-01-10

7.0.0 → 8.0.02024-06-21

8.1.0 → 9.0.02024-07-30

9.0.2 → 10.0.02025-06-24

PHP version history (7 changes)1.0PHP ^7.0

2.0.3PHP &gt;=5.6

4.0.0PHP ^7.3

v4.1.0PHP ^7.3 || ^8.0

7.0.0PHP ^8.1

9.0.0PHP ^8.2

9.0.2PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/da7f64306e4b36d82d5e81b519828b19f6d55861138349f51fa86b6d8239f773?d=identicon)[bigcommerce](/maintainers/bigcommerce)

---

Top Contributors

[![TomA-R](https://avatars.githubusercontent.com/u/1606901?v=4)](https://github.com/TomA-R "TomA-R (16 commits)")[![petrkotek](https://avatars.githubusercontent.com/u/5679032?v=4)](https://github.com/petrkotek "petrkotek (13 commits)")[![repzy](https://avatars.githubusercontent.com/u/8057340?v=4)](https://github.com/repzy "repzy (10 commits)")[![PascalZajac](https://avatars.githubusercontent.com/u/813373?v=4)](https://github.com/PascalZajac "PascalZajac (6 commits)")[![bc-luke](https://avatars.githubusercontent.com/u/2160087?v=4)](https://github.com/bc-luke "bc-luke (6 commits)")[![precariouspanther](https://avatars.githubusercontent.com/u/1628237?v=4)](https://github.com/precariouspanther "precariouspanther (5 commits)")[![funivan](https://avatars.githubusercontent.com/u/425208?v=4)](https://github.com/funivan "funivan (2 commits)")[![bc-vincent-zhao](https://avatars.githubusercontent.com/u/2160148?v=4)](https://github.com/bc-vincent-zhao "bc-vincent-zhao (2 commits)")[![mjhmatt](https://avatars.githubusercontent.com/u/9570178?v=4)](https://github.com/mjhmatt "mjhmatt (1 commits)")

---

Tags

testdipimpleinjector

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bigcommerce-mock-injector/health.svg)

```
[![Health](https://phpackages.com/badges/bigcommerce-mock-injector/health.svg)](https://phpackages.com/packages/bigcommerce-mock-injector)
```

###  Alternatives

[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[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)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2021.0M277](/packages/drupal-core-dev)[fr3d/swagger-assertions

Test your API requests and responses against your swagger definition

138850.9k5](/packages/fr3d-swagger-assertions)[innmind/black-box

Test library

44178.7k93](/packages/innmind-black-box)

PHPackages © 2026

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