Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Deep Closure Comparator Laravel Package

eliashaeussler/deep-closure-comparator

PHPUnit comparator/assertion that deeply compares closures inside objects/arrays by serializing them via opis/closure. Use DeepClosureAssert::assertEquals() as a drop-in replacement for PHPUnit’s assertEquals when closures should be treated as equal.

View on GitHub
Deep Wiki
Context7

Deep Closure Comparator

Coverage CGL Tests Supported PHP Versions

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 library.

🔥 Installation

Packagist Packagist Downloads

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

⚡ Usage

Instead of using the self::assertEquals() method of a PHPUnit test case, use the assertEquals method that is shipped within the DeepClosureAssert 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 library, which provides mechanisms to deep inspect and serialize given closures. More information can be found in the official documentation of this library.

🧑‍💻 Contributing

Please have a look at CONTRIBUTING.md.

💎 Credits

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

⭐ License

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

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope