PHPackages                             sirbrillig/phpunit-just-the-snaps - 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. sirbrillig/phpunit-just-the-snaps

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

sirbrillig/phpunit-just-the-snaps
=================================

A lightweight snapshot testing plugin for PHPUnit

16[1 issues](https://github.com/sirbrillig/phpunit-just-the-snaps/issues)PHP

Since Nov 2Pushed 8y ago1 watchersCompare

[ Source](https://github.com/sirbrillig/phpunit-just-the-snaps)[ Packagist](https://packagist.org/packages/sirbrillig/phpunit-just-the-snaps)[ RSS](/packages/sirbrillig-phpunit-just-the-snaps/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHPUnitJustSnaps
================

[](#phpunitjustsnaps)

A snapshot testing library for PHPUnit

Uses the generic snapshot library [just-the-snaps](https://github.com/sirbrillig/just-the-snaps).

**Still under development! API may change!**

Installation
------------

[](#installation)

```
composer require --dev sirbrillig/phpunit-just-the-snaps

```

Usage
-----

[](#usage)

Include the trait `SnapshotAsserter` in your test class to get access to the methods of this package.

```
use PHPUnitJustSnaps\SnapshotAsserter;

class MyTest extends \PHPUnit\Framework\TestCase {
	use SnapshotAsserter;
}
```

For this example, assume we have a function called `getData()` which returns an array.

```
public function testDataHasNotChanged() {
	$actual = getData();
	$this->assertMatchesSnapshot($actual);
}
```

The first time this code is run, the test will be marked as "skipped" and the data being tested (`$actual`) will be serialized to the file `tests/__snapshots__/testThatFooIsBar.snap`.

The second time (and all subsequent times) this code is run, it will compare the data being tested with the contents of the snapshot file and return true or false depending on if it is the same.

This will protect against any regressions in `getData()`.

If the results of `getData()` change *intentionally*, then the test can be "reset" by simply deleting the snapshot file. The next time the test is run, it will re-create it as above.

Serializers
-----------

[](#serializers)

JustSnaps will run `json_encode()` on any data before writing it to the snapshot file. If your data needs some manipulation before being written, you can create custom serializers.

Each serializer consists of two objects:

1. A class implementing `SerializerTester` which has one function: `shouldSerialize(mixed $data): bool`. This function must return true if the serializer should modify the data.
2. A class implementing `SerializerPrinter` which has one function: `serializeData(mixed $data): mixed`. This function can manipulate the data and then must return the new data which will be written to the snapshot file. Note that the data returned from `serializeData()` will still be passed through `json_encode()` prior to writing.

Here's an example of using a custom serializer to hide sensitive information.

```
use JustSnaps\SerializerPrinter;
use JustSnaps\SerializerTester;
use JustSnaps\Serializer;

public function addSecretSerializer() {
	$printer = new class implements SerializerPrinter {
		public function serializeData($outputData) {
			$outputData['secret'] = 'xxx';
			return $outputData;
		}
	};
	$tester = new class implements SerializerTester {
		public function shouldSerialize($outputData): bool {
			return is_array($outputData) && isset($outputData['secret']);
		}
	};
	$this->addSnapshotSerializer(new Serializer($tester, $printer));
}

public function testDataHasNotChanged() {
	$actual = [ 'foo' => 'bar', 'secret' => 'thisisasecretpassword' ];
	$this->addSecretSerializer();
	$this->assertMatchesSnapshot($actual);
}
```

Similar projects
----------------

[](#similar-projects)

- [phpunit-snapshot-assertions](https://github.com/spatie/phpunit-snapshot-assertions)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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/c17eab4ecec5bcaae35d25bc7bb56358b3d8c2e6e9a3f7e99d480e31260a52a7?d=identicon)[sirbrillig](/maintainers/sirbrillig)

---

Top Contributors

[![sirbrillig](https://avatars.githubusercontent.com/u/2036909?v=4)](https://github.com/sirbrillig "sirbrillig (12 commits)")

### Embed Badge

![Health badge](/badges/sirbrillig-phpunit-just-the-snaps/health.svg)

```
[![Health](https://phpackages.com/badges/sirbrillig-phpunit-just-the-snaps/health.svg)](https://phpackages.com/packages/sirbrillig-phpunit-just-the-snaps)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/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.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/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.1k](/packages/orchestra-testbench)

PHPackages © 2026

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