Skip to content

addition: PHPUnit Eloquent model comparator#15

Merged
remipelhate merged 3 commits into
mainfrom
addition/eloquent-model-comparator
Aug 21, 2025
Merged

addition: PHPUnit Eloquent model comparator#15
remipelhate merged 3 commits into
mainfrom
addition/eloquent-model-comparator

Conversation

@remipelhate

@remipelhate remipelhate commented Aug 21, 2025

Copy link
Copy Markdown
Member

This PR adds a comparator for PHPUnit's IsEqual assertion to compare Eloquent models. Instead of comparing entire objects, the comparator relies on Eloquents Model::is() method.

To enable the comparator, register it to PHPUnit in the Laravel base test case of your project:

namespace App\Shared\Testing;

use Craftzing\TestBench\Laravel\Constraint\Eloquent\ModelComparator;
use SebastianBergmann\Comparator\Factory;

abstract class TestCase extends IlluminateTestCase
{
    #[Before]
    public function setupConstraints(): void
    {
        Factory::getInstance()->register(new ModelComparator());
    }
}

@remipelhate remipelhate self-assigned this Aug 21, 2025
The assert.exception option may not be enabled for projects using this package.
@remipelhate remipelhate merged commit 274eb3b into main Aug 21, 2025
4 checks passed
@remipelhate remipelhate deleted the addition/eloquent-model-comparator branch August 21, 2025 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant