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

Abandoned → [sebastian/comparator](/?search=sebastian%2Fcomparator)ArchivedLibrary[Testing &amp; Quality](/categories/testing)

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

Provides a PHPUnit comparator to assert equality of closures

1.2.3(3w ago)081.7k—5.7%[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 3w 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 2d ago

READMEChangelog (7)Dependencies (22)Versions (12)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)

Important

**Abandoned!** This library was created in response to a [change](https://github.com/sebastianbergmann/comparator/commit/80b4388b7129ea8409681026dea05a85cf310d1b)within the `sebastian/comparator` library. Since the underlying comparison mechanism was [updated](https://github.com/sebastianbergmann/comparator/commit/687a828b212884cdfba0da8d410feb7ad34e73ab)in the meanwhile, this library is no longer necessary and is therefore abandoned. Please switch back to `sebastian/comparator` (versions 7.1.8, 8.2.1 and onwards).

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

53

—

FairBetter than 96% of packages

Maintenance94

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 78.7% 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 ~47 days

Recently: every ~71 days

Total

7

Last Release

26d 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://avatars.githubusercontent.com/u/16313625?v=4)[Elias Häußler](/maintainers/eliashaeussler)[@eliashaeussler](https://github.com/eliashaeussler)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (133 commits)")[![eliashaeussler](https://avatars.githubusercontent.com/u/16313625?v=4)](https://github.com/eliashaeussler "eliashaeussler (36 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

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k955.1M155.1k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k136.1M985](/packages/brianium-paratest)[drupal/core-dev

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

2022.6M343](/packages/drupal-core-dev)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

30314.4k7](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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