Skip to content

Commit b5d99f2

Browse files
Readme
1 parent 60e62c4 commit b5d99f2

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
[![StyleCI](https://styleci.io/repos/75926188/shield?branch=master)](https://styleci.io/repos/75926188)
88
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/phpunit-snapshot-assertions.svg?style=flat-square)](https://packagist.org/packages/spatie/phpunit-snapshot-assertions)
99

10+
> Snapshot testing is a way to test without writing actual test cases
11+
12+
Write a snapshot test:
13+
1014
```php
1115
use Spatie\Snapshots\MatchesSnapshots;
1216

@@ -17,28 +21,56 @@ class OrderSerializerTest
1721
class test_it_serializes_an_order_json()
1822
{
1923
$serializer = new JsonOrderSerializer();
24+
$orderId = new Order(1);
2025

21-
$this->assertMatchesJsonSnapshot($serializer->serialize(new Order(1));
26+
$this->assertMatchesJsonSnapshot($serializer->serialize($order);
2227
}
2328
}
2429
```
30+
31+
Creates a snapshot on first run.
32+
2533
```
2634
> ./vendor/bin/phpunit
2735
2836
There was 1 incomplete test:
2937
30-
1) ExampleTest::test_it_matches_a_string
31-
Snapshot created for OrderSerializerTest__test_it_serializes_an_order_json
38+
1) OrderSerializerTest::test_it_serializes_an_order_json
39+
Snapshot created for OrderSerializerTest__test_it_serializes_an_order_json__1
3240
3341
OK, but incomplete, skipped, or risky tests!
3442
Tests: 1, Assertions: 0, Incomplete: 1.
3543
```
44+
45+
Passes on subsequent runs...
46+
3647
```
3748
> ./vendor/bin/phpunit
3849
3950
OK (1 test, 1 assertion)
4051
```
4152

53+
Unless there's a regression!
54+
55+
```php
56+
$orderId = new Order(2); // Regression! Was `1`
57+
```
58+
```
59+
> ./vendor/bin/phpunit
60+
61+
1) OrderSerializerTest::test_it_serializes_an_order_json
62+
Failed asserting that two strings are equal.
63+
--- Expected
64+
+++ Actual
65+
@@ @@
66+
Failed asserting that '{"id":2}' matches JSON string "{
67+
"id": 1
68+
}
69+
70+
FAILURES!
71+
Tests: 1, Assertions: 1, Failures: 1.
72+
```
73+
4274
## Postcardware
4375

4476
You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

0 commit comments

Comments
 (0)