PHPackages                             eliashaeussler/deep-closure-comparator - 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. eliashaeussler/deep-closure-comparator

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

eliashaeussler/deep-closure-comparator
======================================

Provides a PHPUnit comparator to assert equality of closures

1.2.2(3mo ago)055.8k↓25.2%[1 issues](https://github.com/eliashaeussler/deep-closure-comparator/issues)3GPL-3.0-or-laterPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Aug 25Pushed 2mo agoCompare

[ Source](https://github.com/eliashaeussler/deep-closure-comparator)[ Packagist](https://packagist.org/packages/eliashaeussler/deep-closure-comparator)[ RSS](/packages/eliashaeussler-deep-closure-comparator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (11)Versions (8)Used By (3)

Deep Closure Comparator
=======================

[](#deep-closure-comparator)

[![Coverage](https://camo.githubusercontent.com/575535952279f2adf8af420b65f17009322e104e18298bd005308380f38f4220/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c73436f7665726167652f6769746875622f656c6961736861657573736c65722f646565702d636c6f737572652d636f6d70617261746f723f6c6f676f3d636f766572616c6c73)](https://coveralls.io/github/eliashaeussler/deep-closure-comparator)[![CGL](https://camo.githubusercontent.com/c154ff7ebfb87dc6e412d255a11c1a4c3f9740885f93d9fb3711f86bfefa5fcb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656c6961736861657573736c65722f646565702d636c6f737572652d636f6d70617261746f722f63676c2e79616d6c3f6c6162656c3d63676c266c6f676f3d676974687562)](https://github.com/eliashaeussler/deep-closure-comparator/actions/workflows/cgl.yaml)[![Tests](https://camo.githubusercontent.com/d9d6e0fffdc34d628e76e3d899eae6f209ca5ed87e02e62f217b8ff4a0e49194/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656c6961736861657573736c65722f646565702d636c6f737572652d636f6d70617261746f722f74657374732e79616d6c3f6c6162656c3d7465737473266c6f676f3d676974687562)](https://github.com/eliashaeussler/deep-closure-comparator/actions/workflows/tests.yaml)[![Supported PHP Versions](https://camo.githubusercontent.com/4f9e8953f04d0f1d8dab540b8e51204ca721ce5f7b2a5a6eaec862d15db2de92/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f656c6961736861657573736c65722f646565702d636c6f737572652d636f6d70617261746f722f7068703f6c6f676f3d706870)](https://packagist.org/packages/eliashaeussler/deep-closure-comparator)

A Composer library that provides a PHPUnit comparator to assert equality of closures. It can be used to perform deep evaluation of closures, e.g. as part of objects. Closures are compared using their serialized value, which is calculated by the [`opis/closure`](https://github.com/opis/closure)library.

🔥 Installation
--------------

[](#-installation)

[![Packagist](https://camo.githubusercontent.com/e786bf25295c14c50bf7e8a884dc701b1171b91eb5b44cdbc2b2d94136369007/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6961736861657573736c65722f646565702d636c6f737572652d636f6d70617261746f723f6c6162656c3d76657273696f6e266c6f676f3d7061636b6167697374)](https://packagist.org/packages/eliashaeussler/deep-closure-comparator)[![Packagist Downloads](https://camo.githubusercontent.com/9da10e079b27eca26e18a99b0ff10355d6cb50141c59eb70ffc8eef8ce757ec4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6961736861657573736c65722f646565702d636c6f737572652d636f6d70617261746f723f636f6c6f723d627269676874677265656e)](https://packagist.org/packages/eliashaeussler/deep-closure-comparator)

```
composer require --dev eliashaeussler/deep-closure-comparator
```

⚡ Usage
-------

[](#-usage)

Instead of using the `self::assertEquals()` method of a PHPUnit test case, use the `assertEquals`method that is shipped within the [`DeepClosureAssert`](src/DeepClosureAssert.php) class:

```
use EliasHaeussler\DeepClosureComparator\DeepClosureAssert;
use PHPUnit\Framework\TestCase;

final class Foo
{
    public function __construct(
        public ?\Closure $bar = null,
    ) {}
}

final class FooTest extends TestCase
{
    public function testSomething(): void
    {
        $expected = new Foo();
        $expected->bar = static fn() => 'foo';

        $actual = new Foo();
        $actual->bar = static fn() => 'foo';

        DeepClosureAssert::assertEquals($expected, $actual);
    }
}
```

Or, in other words:

```
-self::assertEquals($expected, $actual);
+DeepClosureAssert::assertEquals($expected, $actual);
```

Note

Closures are compared using their serialized representation. This is done by the [`opis/closure`](https://github.com/opis/closure) library, which provides mechanisms to deep inspect and serialize given closures. More information can be found in the [official documentation](https://opis.io/closure) of this library.

🧑‍💻 Contributing
----------------

[](#‍-contributing)

Please have a look at [`CONTRIBUTING.md`](CONTRIBUTING.md).

💎 Credits
---------

[](#-credits)

This project developed from a hardened implementation detail in the [`sebastian/comparator`](https://github.com/sebastianbergmann/comparator/issues/128) library, as part of PHPUnit's supply chain. With the introduction of a new `ClosureComparator`, comparing closures got a lot more difficult. Finally, [@tstarling](https://github.com/tstarling) suggested parts of the actual implementation of this `deep-closure-comparator` library. Thank you very much for your support!

⭐ License
---------

[](#-license)

This project is licensed under [GNU General Public License 3.0 (or later)](LICENSE).

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance85

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.2% 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 ~34 days

Recently: every ~42 days

Total

6

Last Release

96d ago

PHP version history (2 changes)1.0.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0

1.2.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/144cefe55242b883c87cb537463f3ba75a0f8198fc5b602b50c838aae31fe7ee?d=identicon)[eliashaeussler](/maintainers/eliashaeussler)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (88 commits)")[![eliashaeussler](https://avatars.githubusercontent.com/u/16313625?v=4)](https://github.com/eliashaeussler "eliashaeussler (26 commits)")

---

Tags

closurecomparatorphpunit

### Embed Badge

![Health badge](/badges/eliashaeussler-deep-closure-comparator/health.svg)

```
[![Health](https://phpackages.com/badges/eliashaeussler-deep-closure-comparator/health.svg)](https://phpackages.com/packages/eliashaeussler-deep-closure-comparator)
```

###  Alternatives

[codeception/codeception

All-in-one PHP Testing Framework

4.9k86.2M2.9k](/packages/codeception-codeception)[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)
