# PHPUnit 10.5: SnapshotAssertionFailedException: Snapshot "tests/__snapshots__/UserProfileTest__test_render__1.snap" does not match the expected snapshot. Use --update-snapshots to update.

- **ID:** `php/phpunit-snapshot-assertion-failure`
- **Domain:** php
- **Category:** test_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The snapshot file on disk differs from the current test output, usually due to an intentional UI change, a dependency update altering rendered HTML, or an accidental modification of the snapshot file.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| phpunit/phpunit:10.5.0 | active | — | — |
| spatie/phpunit-snapshot-assertions:5.2.0 | active | — | — |

## Workarounds

1. **If the change is intentional, run the test suite with the --update-snapshots flag to overwrite the snapshot file: 'vendor/bin/phpunit --update-snapshots'** (95% success)
   ```
   If the change is intentional, run the test suite with the --update-snapshots flag to overwrite the snapshot file: 'vendor/bin/phpunit --update-snapshots'
   ```
2. **Inspect the diff using PHPUnit's default output or a tool like 'git diff tests/__snapshots__/' to verify the change is correct, then commit the updated snapshot file.** (90% success)
   ```
   Inspect the diff using PHPUnit's default output or a tool like 'git diff tests/__snapshots__/' to verify the change is correct, then commit the updated snapshot file.
   ```
3. **If the snapshot is corrupted, restore it from version control: 'git checkout -- tests/__snapshots__/UserProfileTest__test_render__1.snap'** (85% success)
   ```
   If the snapshot is corrupted, restore it from version control: 'git checkout -- tests/__snapshots__/UserProfileTest__test_render__1.snap'
   ```

## Dead Ends

- **** — Deleting the entire __snapshots__ directory and rerunning tests causes all snapshots to be recreated, but this discards the intended baseline for other tests, leading to false positives or missed regressions. (70% fail)
- **** — Manually editing the snapshot file to match expected output often introduces formatting inconsistencies (e.g., trailing whitespace, line endings), which can cause the assertion to still fail or produce a different diff. (60% fail)
- **** — Running tests with --verbose or --debug without --update-snapshots does not resolve the mismatch; it only provides more output details but does not update the file. (100% fail)
