PHPackages                             alexskrypnyk/snapshot - 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. alexskrypnyk/snapshot

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

alexskrypnyk/snapshot
=====================

Directory snapshot, diff, and patch system useful for test fixtures.

1.3.0(2mo ago)16.5k↓23.3%[1 issues](https://github.com/AlexSkrypnyk/snapshot/issues)GPL-2.0-or-laterPHPPHP &gt;=8.2CI passing

Since Dec 17Pushed 2mo agoCompare

[ Source](https://github.com/AlexSkrypnyk/snapshot)[ Packagist](https://packagist.org/packages/alexskrypnyk/snapshot)[ Docs](https://github.com/alexskrypnyk/snapshot)[ GitHub Sponsors](https://github.com/alexskrypnyk)[ Patreon](https://www.patreon.com/alexskrypnyk)[ RSS](/packages/alexskrypnyk-snapshot/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (22)Versions (15)Used By (0)

  ![Snapshot logo](logo.png)

Directory snapshot, diff, and patch system useful for test fixtures
===================================================================

[](#directory-snapshot-diff-and-patch-system-useful-for-test-fixtures)

[![GitHub Issues](https://camo.githubusercontent.com/e6f80cad742bb7f6d28b5e3b0eaf68b786232e4d72441cabd6691ce61415ac41/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f616c6578736b7279706e796b2f736e617073686f742e737667)](https://github.com/alexskrypnyk/snapshot/issues)[![GitHub Pull Requests](https://camo.githubusercontent.com/f9310569690ae1a26ff696fe1cf370456d186a30c157a685658d0fd59f6719b6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f616c6578736b7279706e796b2f736e617073686f742e737667)](https://github.com/alexskrypnyk/snapshot/pulls)[![Test PHP](https://github.com/alexskrypnyk/snapshot/actions/workflows/test-php.yml/badge.svg)](https://github.com/alexskrypnyk/snapshot/actions/workflows/test-php.yml)[![codecov](https://camo.githubusercontent.com/4c3c568954f3f152683d414e35a7602f5bff192a0f250c5738450830b3b440df/68747470733a2f2f636f6465636f762e696f2f67682f616c6578736b7279706e796b2f736e617073686f742f67726170682f62616467652e7376673f746f6b656e3d37574542314958425954)](https://codecov.io/gh/alexskrypnyk/snapshot)[![GitHub release (latest by date)](https://camo.githubusercontent.com/bbb5d80e6373f8c3d05d6318680eabaeed038daceefa1a7a043eddc1850cf041/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f616c6578736b7279706e796b2f736e617073686f74)](https://camo.githubusercontent.com/bbb5d80e6373f8c3d05d6318680eabaeed038daceefa1a7a043eddc1850cf041/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f616c6578736b7279706e796b2f736e617073686f74)[![LICENSE](https://camo.githubusercontent.com/023683140985944f3c26f13e364e8889399939e7fbe73d2be6c039c41cbf9f9c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616c6578736b7279706e796b2f736e617073686f74)](https://camo.githubusercontent.com/023683140985944f3c26f13e364e8889399939e7fbe73d2be6c039c41cbf9f9c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616c6578736b7279706e796b2f736e617073686f74)[![Renovate](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)

---

Features
--------

[](#features)

- **Directory comparison** - Compare two directories for identical structure and content
- **Baseline + diff architecture** - Store a baseline once, then only diffs per test scenario
- **Unified diff format** - Human-readable patch files that can be reviewed in PRs
- **Auto-update snapshots** - Automatically update snapshots when tests fail
- **Flexible ignore rules** - Skip files, directories, or ignore content differences
- **PHPUnit integration** - Simple trait with intuitive assertions

Use Cases
---------

[](#use-cases)

This library is designed for testing systems that generate file output:

- **Template repositories** - Test scaffolds, skeletons, and boilerplate generators to ensure customization options produce the expected file structure
- **Code generators** - Verify that generated code matches expected output across different configuration scenarios
- **Build tools** - Assert that compilation or transformation processes produce correct artifacts
- **Migration scripts** - Validate that file transformations work correctly

For example, if you maintain a project template with customizable options (like choosing a database driver or enabling optional features), you can use this library to test each combination of options produces the correct files.

Concepts
--------

[](#concepts)

### Baseline

[](#baseline)

A **baseline** is a reference directory containing the expected file structure and content. It represents the "golden master" that your test output is compared against.

```
fixtures/
└── _baseline/           # The baseline directory
    ├── composer.json
    ├── src/
    │   └── App.php
    └── README.md

```

### Snapshot (Scenario)

[](#snapshot-scenario)

A **snapshot** (or scenario) represents differences from the baseline for a specific test case. Instead of duplicating the entire expected output, you only store the files that differ.

```
fixtures/
├── _baseline/           # Shared baseline
│   └── ...
├── scenario_mysql/      # Only files that differ for MySQL option
│   └── config/
│       └── database.php
└── scenario_postgres/   # Only files that differ for PostgreSQL option
    └── config/
        └── database.php

```

### Diff Files

[](#diff-files)

Snapshot directories contain **diff files** in unified diff format. These describe how a file should differ from its baseline version:

```
@@ -1,8 +1,8 @@
