spatie/pest-plugin-snapshots
Adds snapshot testing to Pest via Spatie’s snapshot assertions. Compare strings or JSON against stored snapshots with helper functions or Pest expectations. Ideal for stable output/regression testing in PHP projects.
expect() syntax and it() blocks, ensuring zero disruption to existing test suites. Aligns with Laravel’s growing adoption of Pest as the default testing framework.phpunit-snapshot-assertions), covering 90% of Laravel output validation needs without additional tooling.phpunit-snapshot-assertions (v5.3.1+), ensuring long-term stability and shared ecosystem benefits (e.g., diff tools, CI integrations).composer require with no config changes required. Works with Pest v2/v3 and Laravel 8+.$this->get(), $this->actingAs()) and Laravel’s HTTP clients, ensuring no learning curve for developers.--update-snapshots) and integrates with GitHub/GitLab diff tools for visual feedback..gitignore or CI-based snapshot storage).phpunit-snapshot-assertions (v5.3.1+), but Spatie’s active maintenance (2.3.1 released in 2026) reduces risk.toMatchSnapshot()) and assertion functions (assertMatchesSnapshot()), aligning with Laravel’s modern testing stack.$this->get(), $this->post()).assertJson() with toMatchSnapshot().assertMatchesSnapshot().assertMatchesSnapshot().--update-snapshots for intentional changes..gitignore or S3 to avoid repo bloat.spatie/phpunit-snapshot-assertions (v5.3.1+).composer require spatie/pest-plugin-snapshots --dev
$response->assertJson(['key' => 'value']);
with:
expect($response->json())->toMatchSnapshot();
--update-snapshots to generate baseline snapshots.toMatchSnapshot()).--update-snapshots).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Snapshot Drift | False negatives (missed regressions) | Use --update-snapshots for intentional changes |
| Non-Deterministic Data | Flaky tests (timestamps, UUIDs) | Pre-process data (e.g., str_replace()) |
| Large Snapshot Files | Slow CI/CD, repo bloat | Store externally (S3) or use .gitignore |
| Team Resistance | Low adoption | Pilot with high-impact tests first |
| Image Format Limitations | Can’t test PDFs/CSVs | Use custom pre-processing or other tools |
| CI/CD Misconfiguration | Broken snapshot updates | Template CI config with snapshot validation |
How can I help you explore Laravel packages today?