You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To make snapshot assertions, use the `Spatie\Snapshots\MatchesSnapshots` trait in your test case class. This adds four assertion methods to the class:
81
+
To make snapshot assertions, use the `Spatie\Snapshots\MatchesSnapshots` trait in your test case class. This adds five assertion methods to the class:
82
82
83
83
-`assertMatchesSnapshot($actual)`
84
84
-`assertMatchesJsonSnapshot($actual)`
85
85
-`assertMatchesXmlSnapshot($actual)`
86
+
-`assertMatchesFileSnapshot($filePath)`
86
87
-`assertMatchesFileHashSnapshot($filePath)`
87
88
88
89
### Snapshot Testing 101
@@ -159,6 +160,14 @@ As a result, our snapshot file returns "bar" instead of "foo".
159
160
<?php return 'bar';
160
161
```
161
162
163
+
### File snapshots
164
+
165
+
The `MatchesSnapshots` trait offers two ways to assert that a file is identical to the snapshot that was made the first time the test was run:
166
+
167
+
The `assertMatchesFileHashSnapshot($filePath)` assertion asserts that the hash of the file passed into the function and the hash saved in the snapshot match. This assertion is fast and uses very little disk space. The downside of this assertion is that there is no easy way to see how the two files differ if the test fails.
168
+
169
+
The `assertMatchesFileSnapshot($filePath)` assertion works almost the same way as the file hash assertion, except that it actually saves the whole file in the snapshots directory. If the assertion fails, it places the failed file next to the snapshot file so they can easily be manually compared. The persisted failed file is automatically deleted when the test passes. This assertion is most useful when working with binary files that should be manually compared like images or pdfs.
170
+
162
171
### Customizing Snapshot Ids and Directories
163
172
164
173
Snapshot ids are generated via the `getSnapshotId` method on the `MatchesSnapshot` trait. Override the method to customize the id. By default, a snapshot id exists of the test name, the test case name and an incrementing value, e.g. `Test__my_test_case__1`.
0 commit comments