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
=============================

01121PHP

Since May 19Pushed 3y 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 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

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

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M679](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M753](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M571](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.0k](/packages/orchestra-testbench)

PHPackages © 2026

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