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

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

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

A snapshot testing library for PHP

113PHP

Since Nov 3Pushed 8y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

JustSnaps
=========

[](#justsnaps)

A snapshot testing library for PHP

This library intends to be:

- Very low developer friction.
- Test runner agnostic.
- Lightweight.

See [phpunit-just-the-snaps](https://github.com/sirbrillig/phpunit-just-the-snaps) for a PHPUnit plugin that uses this library.

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

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

[](#installation)

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

```

Generic Usage
-------------

[](#generic-usage)

This is how to use JustSnaps without any particular test runner.

For this example, assume we have a function called `getData()` which returns an array, and one called `assertTrue()` which throws an exception if its expression is not `true`.

```
$actual = getData();
$asserter = \JustSnaps\buildSnapshotAsserter('./tests/__snapshots__');
assertTrue($asserter->forTest('testThatFooIsBar')->assertMatchesSnapshot($actual));
```

The first time this code is run, a `CreatedSnapshotException` will be thrown 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.

```
$actual = [ 'foo' => 'bar', 'secret' => 'thisisasecretpassword' ];
$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']);
	}
};
$serializer = new Serializer($tester, $printer);
$asserter = \JustSnaps\buildSnapshotAsserter('./tests/__snapshots__');
$asserter->addSerializer($serializer);
assertTrue($asserter->forTest('testThatFooIsBar')->assertMatchesSnapshot($actual));
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

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 (40 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/sirbrillig-just-the-snaps/health.svg)](https://phpackages.com/packages/sirbrillig-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)
