PHPackages                             thenlabs/snapshots-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. thenlabs/snapshots-comparator

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

thenlabs/snapshots-comparator
=============================

011611PHP

Since May 19Pushed 4y agoCompare

[ Source](https://github.com/thenlabs/snapshots-comparator)[ Packagist](https://packagist.org/packages/thenlabs/snapshots-comparator)[ RSS](/packages/thenlabs-snapshots-comparator/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (1)

SnapshotsComparator
===================

[](#snapshotscomparator)

Comparison of state arrays with expectations.

#### If you like this project gift us a ⭐.

[](#if-you-like-this-project-gift-us-a-)

---

Installation.
-------------

[](#installation)

```
composer require thenlabs/snapshots-comparator dev-main

```

Usage example.
--------------

[](#usage-example)

We have the next two status vars:

```
$before = [
    'document1' => [
        'id' => '1',
        'title' => 'The document 1',
        'customData1' => 'custom data 1',
    ]
];

$after = [
    'document1' => [
        'id' => '1',
        'title' => 'The document one',
        'anotherData' => 'another data',
    ]
];
```

When we compare both(without declaring expectations) we obtain the next results:

```
use ThenLabs\SnapshotsComparator\Comparator;

$result = Comparator::compare($before, $after);

false === $result->isSuccessful(); // becouse there are unexpectations.

$result->getUnexpectations() === [
    'CREATED' => [
        'document1' => [
            // 'anotherData' was created.
            'anotherData' => 'another data',
        ]
    ],
    'UPDATED' => [
        'document1' => [
            // 'title' was updated
            'title' => 'The document one',
        ]
    ],
    'DELETED' => [
        'document1' => [
            // 'customData1' was deleted
            'customData1' => 'custom data 1',
        ]
    ],
];
```

We can see that we obtain all the information about the difference between before and after, as example, which data they was created, updated or deleted.

All these changes they was unexpected becouse we not declaring expectations, and that is the reason for which `$result->isSuccessful()` returns `false.`

In the next example we declare all the expectations and that way accomplish a successful result without unexpectations.

```
use ThenLabs\SnapshotsComparator\Comparator;
use ThenLabs\SnapshotsComparator\ExpectationBuilder;

$expectations = new ExpectationBuilder();

$expectations->expectCreated([
    'document1' => [
        'anotherData' => 'another data',
    ]
]);

$expectations->expectUpdated([
    'document1' => [
        'title' => function ($value) { // custom comparator
            return is_string($value);
        },
    ]
]);

$expectations->expectDeleted([
    'document1' => [
        'customData1' => 'custom data 1',
    ]
]);

$result = Comparator::compare($before, $after, $expectations);

true === $result->isSuccessful();
[] === $result->getUnexpectations();
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff9241f3ee1e25a0a016399ff1ae829fea13ed7493c62627ac5068ae61c39197?d=identicon)[andaniel05](/maintainers/andaniel05)

---

Top Contributors

[![andaniel05](https://avatars.githubusercontent.com/u/21297818?v=4)](https://github.com/andaniel05 "andaniel05 (8 commits)")

---

Tags

phpsnapshot-testingsnapshotsstatestestingtesting-tools

### Embed Badge

![Health badge](/badges/thenlabs-snapshots-comparator/health.svg)

```
[![Health](https://phpackages.com/badges/thenlabs-snapshots-comparator/health.svg)](https://phpackages.com/packages/thenlabs-snapshots-comparator)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M360](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

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