PHPackages                             forknetwork/strict-phpunit - 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. forknetwork/strict-phpunit

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

forknetwork/strict-phpunit
==========================

A simple PHPUnit extension that disallows unexpected method calls.

v2.2.0(2y ago)232.1k↑70%Apache-2.0PHPPHP &gt;=7.4

Since Jan 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ForkNetwork/StrictPHPUnit)[ Packagist](https://packagist.org/packages/forknetwork/strict-phpunit)[ RSS](/packages/forknetwork-strict-phpunit/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

StrictPHPUnit
=============

[](#strictphpunit)

[![Latest version](https://camo.githubusercontent.com/8c823ad4c6c4138b7a79dd2013c1fdd577b444c87e7360ada4fbdcf74374c1fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f726b6e6574776f726b2f7374726963742d706870756e69742e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d303037454336)](https://packagist.org/packages/forknetwork/strict-phpunit)[![Downloads](https://camo.githubusercontent.com/b2596ccc0e7a3fee507a322a391307fbc5d48502dea39dde557e53868e564d9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f726b6e6574776f726b2f7374726963742d706870756e69742e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d303037454336)](https://packagist.org/packages/forknetwork/strict-phpunit)[![Travis build status](https://camo.githubusercontent.com/ba66e2088f1977b407f98fef81720d85748b3ac3cdf078ef4a6ade2577cbde84/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f466f726b4e6574776f726b2f537472696374504850556e69742f6d61737465722e7376673f6c6162656c3d747261766973267374796c653d666c61742d737175617265)](https://travis-ci.org/ForkNetwork/StrictPHPUnit)

A simple PHPUnit extension that disallows unexpected method calls.

For PHPUnit 7.1 and up.

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

[](#installation)

```
composer require forknetwork/strict-phpunit ^2.0
```

How to use
----------

[](#how-to-use)

The `StrictTestTrait` can be used by any class that extends from `TestCase` of PHPUnit. This trait can be added automatically using the PHP Code Sniffer.

**Before**

```
use PHPUnit\Framework\TestCase;

class YourTest extends TestCase
{
    // ...
}
```

**After**

```
use ForkNetwork\StrictPHPUnit\StrictTestTrait;
use PHPUnit\Framework\TestCase;

class YourTest extends TestCase
{
    use StrictTestTrait;
    // ...
}
```

### Overwrite strict mock generation

[](#overwrite-strict-mock-generation)

By default all mocks will be strict, but in some cases that won't work. For example, PHPUnit doesn't handle the destruct method for mocks well. In those cases you might want to enable the value generation again.

**Before**

```
private function createFooMock()
{
    return $this->createMock('\Bar\Foo');
}
```

**After**

```
private function createFooMock()
{
    return $this->getMockBuilder('\Bar\Foo')
        ->enableAutoReturnValueGeneration();
        ->getMock();
}
```

Another option would to remove the trait from the class and manually add `->disableAutoReturnValueGeneration()` onto the mocks your want strict.

Optional: PHP code sniffer and fixer
------------------------------------

[](#optional-php-code-sniffer-and-fixer)

This library comes with a code sniff with auto-fixer. Just include the reference in your `phpcs.xml(.dist)` file and run the code sniffer as usual.

```

```

By default it will sniff all classes that extend from `TestCase` (PHPUnit). You can change which extended class it should sniff by adding this to your configuration.

```

```

Please note that this sniff only ensures the trait and use statements are added. It does not sort or pay attention to the rest of your code style.

**Known limitations**
The current implementation of the sniff doesn't support the following situations:

- Comma separated use trait statements (e.g. `use StrictUnitTrait, FooTrait;`)
- FQCN or partial use trait statements (e.g. `use Traits\StrictUnitTest;`)
- Running the sniff unit tests in PHPUnit 8 or higher is not supported.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~646 days

Total

4

Last Release

782d ago

Major Versions

v1.0.0 → v2.0.02019-03-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e11593b3c7e3bc3ae90c4a4c919b0fb4c11d55ac16fb2e0ddfaf2413803bd02?d=identicon)[Gadgetdude](/maintainers/Gadgetdude)

---

Top Contributors

[![RolfBabijn](https://avatars.githubusercontent.com/u/3118677?v=4)](https://github.com/RolfBabijn "RolfBabijn (8 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/forknetwork-strict-phpunit/health.svg)

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

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k129.9M910](/packages/brianium-paratest)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k41.3M38.7k](/packages/orchestra-testbench)[drupal/core-dev

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

2022.0M321](/packages/drupal-core-dev)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

30300.1k6](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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