Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpunit Snapshot Assertions Laravel Package

spatie/phpunit-snapshot-assertions

Add snapshot testing to PHPUnit. Assert strings, JSON, arrays, and objects against saved snapshots; first run writes snapshots, later runs compare and fail on regressions. Simple trait-based API (e.g., assertMatchesJsonSnapshot) for PHP and Laravel projects.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Shift from brittle unit tests to maintainable integration/behavioral tests: Reduces test maintenance overhead for APIs, UI outputs, or complex data transformations by automating snapshot comparisons.
  • Accelerate CI/CD feedback loops: Enables faster test execution for regression detection in UI, JSON responses, or file outputs without manual test updates.
  • Leverage Laravel’s ecosystem: Complements existing Laravel testing tools (e.g., Pest, Laravel Dusk) for end-to-end testing of templates, API responses, or CLI outputs.
  • Build vs. Buy: Avoid reinventing snapshot testing infrastructure; adopt a battle-tested, MIT-licensed solution with 695+ stars.
  • Use Cases:
    • API response validation (e.g., GraphQL, REST).
    • Frontend/email template regression testing (HTML, YAML, XML).
    • CLI output consistency (e.g., Artisan commands).
    • File generation (PDFs, images, CSVs) with pixel-perfect or hash-based validation.

When to Consider This Package

  • Adopt if:
    • Your team struggles with flaky or overly verbose tests for dynamic outputs (e.g., API responses, rendered views).
    • You need to detect regressions in complex data structures (JSON, XML, HTML) without manual test updates.
    • CI/CD pipelines require fast, reliable regression checks for non-trivial outputs.
    • You’re using Laravel/PHP and want to integrate with existing test suites (PHPUnit, Pest).
  • Look elsewhere if:
    • Your tests are pure unit tests (e.g., math operations, simple logic) where snapshots add no value.
    • You need stateful testing (e.g., database transactions) beyond snapshot comparisons.
    • Your outputs are highly volatile (e.g., timestamps, UUIDs) and require custom normalization.
    • You’re constrained by legacy PHPUnit versions (<12.5.12) due to CLI argument deprecations.

How to Pitch It (Stakeholders)

For Executives: "This package automates regression testing for our Laravel/PHP outputs—API responses, emails, or UI templates—by comparing them against ‘golden snapshots.’ Instead of manually updating tests when outputs change (e.g., after a refactor), the tool flags unintended changes in CI/CD. For example, if a marketing email template breaks after a deploy, we’ll catch it instantly. It’s like a safety net for our product’s consistency, reducing manual QA effort and shipping confidence."

For Engineers: *"Spatie’s snapshot testing lets us replace verbose assertions (e.g., assertEquals($expectedJson, json_encode($response))) with a single line like assertMatchesJsonSnapshot($response). On first run, it saves the output as a snapshot; subsequent runs fail if the output drifts. Key benefits:

  • Faster test writing: No need to hardcode expected values for complex outputs.
  • CI-friendly: Disable snapshot creation in CI to fail on missing snapshots (e.g., CREATE_SNAPSHOTS=false).
  • Supports Laravel: Works with Pest, Dusk, or PHPUnit for APIs, views, or CLI tools.
  • Customizable: Override snapshot IDs/directories or build custom drivers (e.g., for YAML or images). Example: Test a GraphQL query’s response in one line instead of 20 assertArrayHasKey() calls."*

For QA/DevOps: *"This tool integrates seamlessly with our CI pipeline to catch visual/API regressions early. For instance:

  • Before: A developer changes an email template, but QA misses the broken CSS in staging.
  • After: The snapshot test fails in CI with a diff, alerting the team immediately. We can also use it to validate PDFs or images (with pixel comparison) without manual reviews."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai