use Spatie\Snapshots\MatchesSnapshots;
class OrderTest
{
use MatchesSnapshot;
class test_it_casts_to_json()
{
$orderId = new Order(1);
$this->assertMatchesJsonSnapshot($order->toJson());
}
}
Again great work by the folks at Spatie:
The difference between a classic
assertEquals
and anassertMatchesSnapshot
is that you don’t write the expectation yourself when snapshot testing. When a snapshot assertion happens for the first time, it creates a snapshot file with the actual output, and marks the test as incomplete. Every subsequent run will compare the output with the existing snapshot file to check for regressions.
A Package for Snapshot Testing in PHPUnit →spatie/phpunit-snapshot-assertions
(GitHub) →