Skip to content

Commit 5577c9d

Browse files
Update readme
1 parent 872db06 commit 5577c9d

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Tests: 1, Assertions: 1, Failures: 1.
7070

7171
## Support us
7272

73-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
73+
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
7474

7575
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
7676

@@ -84,14 +84,17 @@ composer require --dev spatie/phpunit-snapshot-assertions
8484

8585
## Usage
8686

87-
To make snapshot assertions, use the `Spatie\Snapshots\MatchesSnapshots` trait in your test case class. This adds five assertion methods to the class:
87+
To make snapshot assertions, use the `Spatie\Snapshots\MatchesSnapshots` trait in your test case class. This adds a set of assertion methods to the class:
8888

8989
- `assertMatchesSnapshot($actual)`
90+
- `assertMatchesFileHashSnapshot($actual)`
91+
- `assertMatchesFileSnapshot($actual)`
92+
- `assertMatchesHtmlSnapshot($actual)`
9093
- `assertMatchesJsonSnapshot($actual)`
94+
- `assertMatchesObjectSnapshot($actual)`
95+
- `assertMatchesTextSnapshot($actual)`
9196
- `assertMatchesXmlSnapshot($actual)`
92-
- `assertMatchesHtmlSnapshot($actual)`
93-
- `assertMatchesFileSnapshot($filePath)`
94-
- `assertMatchesFileHashSnapshot($filePath)`
97+
- `assertMatchesYamlSnapshot($actual)`
9598

9699
### Snapshot Testing 101
97100

@@ -117,10 +120,10 @@ OK, but incomplete, skipped, or risky tests!
117120
Tests: 1, Assertions: 0, Incomplete: 1.
118121
```
119122

120-
Snapshot ids are generated based on the test and testcase's names. Basic snapshots return a `var_export` of the actual value.
123+
Snapshot ids are generated based on the test and testcase's names. Basic snapshots return a plain text or YAML representation of the actual value.
121124

122-
```php
123-
<?php return 'foo';
125+
```txt
126+
foo
124127
```
125128

126129
Let's rerun the test. The test runner will see that there's already a snapshot for the assertion and do a comparison.
@@ -163,16 +166,16 @@ OK (1 test, 1 assertion)
163166

164167
As a result, our snapshot file returns "bar" instead of "foo".
165168

166-
```php
167-
<?php return 'bar';
169+
```txt
170+
bar
168171
```
169172

170173
### File snapshots
171174

172175
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:
173176

174-
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.
175-
177+
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.
178+
176179
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.
177180

178181
### Customizing Snapshot Ids and Directories
@@ -209,18 +212,18 @@ The driver used to serialize the data can be specificied as second argument of t
209212
`assertMatchesSnapshot` method, so you can pick one that better suits your needs:
210213

211214
```php
212-
use Spatie\Snapshots\Drivers\ObjectDriver;
215+
use Spatie\Snapshots\Drivers\JsonDriver;
213216
use Spatie\Snapshots\MatchesSnapshots;
214217

215218
class OrderTest
216219
{
217220
use MatchesSnapshots;
218221

219-
public function test_snapshot_with_object_driver()
222+
public function test_snapshot_with_json_driver()
220223
{
221224
$order = new Order(1);
222225

223-
$this->assertMatchesSnapshot($order, new ObjectDriver());
226+
$this->assertMatchesSnapshot($order->toJson(), new JsonDriver());
224227
}
225228
}
226229
```

0 commit comments

Comments
 (0)