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

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

webmozarts/strict-phpunit
=========================

Enables type-safe comparisons of objects in PHPUnit

7.24.0(1mo ago)31252.7k↓37.9%15MITPHPPHP ^8.3

Since Apr 19Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/webmozarts/strict-phpunit)[ Packagist](https://packagist.org/packages/webmozarts/strict-phpunit)[ RSS](/packages/webmozarts-strict-phpunit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (130)Used By (5)

Strict PHPUnit
==============

[](#strict-phpunit)

Caution

This repository is read-only. To submit any changes, check out \[php-libraries\].

Enables type-safe comparisons of objects in PHPUnit.

Problem
-------

[](#problem)

PHPUnit has a very powerful comparison system that helps you to compare objects with expected values:

```
class ValueObject
{
    public ?string $property;

    public function __construct(?string $property)
    {
        $this->property = $property;
    }
}

$actual = new ValueObject('foo!');

self::assertEquals(new ValueObject('foo'), $actual);
// => fails with a very helpful error message
```

This comparison system will give you a meaningful exception that guides you precisely to the problem that caused the assertion to fail. Strings are furthermore diffed so that you see exactly which character of the string causes a mismatch.

PHPUnit compares each scalar property of an object with relaxed types. It is a little more intelligent than using just `==` under the hood, but still that will not always provide the results you want:

```
var_dump('Hi' == true);
// => true

self::assertEquals(new ValueObject('Hi'), new ValueObject(true));
// => fails

var_dump('' == null);
// => true

self::assertEquals(new ValueObject(''), new ValueObject(null));
// => succeeds
```

Solution
--------

[](#solution)

This extension enables a comparator for scalar values that fights this problem. With this extension, whenever PHPUnit finds a scalar value during `assertEquals()` (even recursively within objects or arrays), it will compare the value with `===`.

Objects are still not checked for identity, hence you can still construct example objects to compare against.

Error messages stay meaningful.

```
self::assertEquals(new ValueObject(''), new ValueObject(null));
// => fails with a meaningful error

self::assertEquals(new ValueObject('foo!'), new ValueObject('foo'));
// => fails with a meaningful error

self::assertEquals(new ValueObject('foo!'), new ValueObject('foo!'));
// => succeeds
```

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

[](#installation)

The extension can be installed with Composer:

```
composer require --dev webmozarts/strict-phpunit
```

Add the extension to your `phpunit.xml.dist` file to enable it:

```

```

Authors
-------

[](#authors)

- [Bernhard Schussek](http://webmozarts.com)
- [The Community Contributors](https://github.com/webmozarts/strict-phpunit/graphs/contributors)

Contribute
----------

[](#contribute)

Contributions to the package are always welcome!

- Report any bugs or issues you find on the [issue tracker](https://github.com/webmozarts/strict-phpunit/issues).
- You can grab the source code at the package's [Git repository](https://github.com/webmozarts/strict-phpunit).

Note that this repository is a subtree-split of a monorepo and hence read only. PRs will be ported to the (internal) monorepo.

License
-------

[](#license)

All contents of this package are licensed under the [MIT license](LICENSE).

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance88

Actively maintained with recent releases

Popularity44

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

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

Total

126

Last Release

59d ago

Major Versions

6.16.6 → 7.19.22025-08-12

PHP version history (3 changes)7.0.0-beta.1PHP &gt;=7.4.0

7.8.x-devPHP ^8.1

7.16.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/00803e109877ea9de0995e81c928871a595781bd6ea227092bfd7c6df5af58f0?d=identicon)[webmozart](/maintainers/webmozart)

---

Top Contributors

[![theofidry](https://avatars.githubusercontent.com/u/5175937?v=4)](https://github.com/theofidry "theofidry (48 commits)")[![webmozart](https://avatars.githubusercontent.com/u/176399?v=4)](https://github.com/webmozart "webmozart (10 commits)")

---

Tags

phpunitstrict-types

### Embed Badge

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

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

###  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)
