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
5.4.0

What's Changed

  • Add vendor/bin/update-snapshots wrapper binary that sets UPDATE_SNAPSHOTS=true and runs PHPUnit. This replaces the previously documented phpunit -d --update-snapshots syntax, which abused PHPUnit's -d flag and produces a Failed to set "--update-snapshots=1" test runner warning since PHPUnit 12.5.12.
  • Drop the phpunit -d --without-creating-snapshots form from the README. Use the CREATE_SNAPSHOTS=false environment variable instead. The argv check is kept in shouldCreateSnapshots() for backwards compatibility.
  • The wrapper restores the prior UPDATE_SNAPSHOTS env var state on shutdown, so it does not leak a state mutation to any in-process code that runs after PHPUnit.
  • Reworded the "Snapshot does not exist" failure message and the "snapshots can be updated by..." prompt to point at the new approach.
  • shouldUpdateSnapshots() and shouldCreateSnapshots() now check the env var first, then fall back to the legacy CLI argument.
  • Fix tests on PHPUnit 12.5+, where mocks throwing AssertionFailedError are tracked as a test failure even when user code catches the exception. The expectFail helper now uses a plain RuntimeException carrying the expected message.

Closes #242.

Full Changelog: https://github.com/spatie/phpunit-snapshot-assertions/compare/5.3.2...5.4.0

5.3.2

What's Changed

  • Fix BC break in getSnapshotId() from named snapshots feature — restored original no-parameter signature
  • Add README documentation for named snapshots
5.3.1

What's Changed

  • Allow PHPUnit 13
5.3.0

What's Changed

Full Changelog: https://github.com/spatie/phpunit-snapshot-assertions/compare/5.2.3...5.3.0

5.2.2

What's Changed

Full Changelog: https://github.com/spatie/phpunit-snapshot-assertions/compare/5.2.1...5.2.2

5.2.1

What's Changed

New Contributors

Full Changelog: https://github.com/spatie/phpunit-snapshot-assertions/compare/5.2.0...5.2.1

5.1.1
  • fix image driver
5.0.1
4.2.12

What's Changed

New Contributors

Full Changelog: https://github.com/spatie/phpunit-snapshot-assertions/compare/4.2.11...4.2.12

4.2.11
4.2.10
4.2.9
4.2.8
4.2.7
  • clean filenames on MatchesFileSnapshot for Windows (#130)
4.2.6
  • allow using env vars to manage snapshot creation and update (#126)
4.2.5
  • add support for PHP 7.3
4.2.4
  • add support for PHP 8
4.2.3
  • migrate phpunit config
4.2.2
  • moves default implementation of snapshot directory/id to concerns directory (#99)
4.2.1
  • Fix exception message
4.2.0
  • Fixed inconsistent line endings
  • Improved Windows support
4.1.0
  • Added --without-creating-snapshots flag
4.0.0

Snapshots generated with assertMatchesSnapshot will break when upgrading to this version. The easiest way to upgrade is to ensure your snapshot tests pass, delete your snapshots, upgrade the package, then rerun the tests to generate new snapshots.

  • New snapshot formats when using assertMatchesSnapshot: scalars (strings, integers & floats) are serialized to txt files, objects & arrays are serialized to yaml files
  • New TextDriver to store snapshots in txt files
  • New ObjectDriver to serialize data to YAML and store snapshots in yaml files
  • Removed VarDriver
3.1.0
  • Drop support for PHP 7.3
3.0.0
  • assertMatchesJsonSnapshot now supports all JSON serializable objects, and won't convert empty arrays to obejcts anymore
2.2.1
  • Allow symfony 5 components
2.2.0
  • Added an assertMatchesHtmlSnapshot assertion
2.1.3
  • Allow recursive mkdir for file snapshots
2.1.2
  • Less restrictive symfony/yaml version requirement
2.1.1
  • Fix for json driver
3.1.1
  • Add support for PHPUnit 9 (#86)
2.1.0
  • Require PHPUnit 8 & PHP 7.2
2.0.0
  • Use YAML by default for associative arrays
  • Drop PHP 7.0 support, the new constraint is ^7.1
  • Drop PHPUnit ^6.5 support, the new constraint is ^7.0
1.4.1
  • Fix JSON array comparisons
1.4.0
  • Allow arrays to be serialized to JSON
1.3.3
  • Fix updating failed file-snapshots
1.3.2
  • Fix for tests with weird characters
1.3.1
  • Lowered minimum required PHPUnit version
1.3.0
  • Only mark test incomplete after every snapshot has been run
1.2.3
  • Fixed snapshot creation in recursive directories
1.2.2
  • Support PHP 7.2
1.2.1
  • Support phpunit ^7.0
1.2.0
  • Added assertMatchesFileSnapshot
1.1.1
  • Fixed assertMatchesFileHashSnapshot
1.1.0
  • Added assertMatchesFileHashSnapshot assertion
1.0.2
  • Added example folder to .gitattributes
1.0.1
  • Fixed expected and actual argument order when making json assertions
1.0.0
  • Added a reminder how to update snapshots when a snapshot assertion fails
0.4.1
  • Initial release
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