Skip to content

Instantly share code, notes, and snippets.

@micc83
Last active January 4, 2019 07:09
Show Gist options
  • Save micc83/3894ea89e209b60a88bbba3870ae84ed to your computer and use it in GitHub Desktop.
Save micc83/3894ea89e209b60a88bbba3870ae84ed to your computer and use it in GitHub Desktop.
PHPUnit Assertion that asserts the response content match a previous taken snapshot
<?php
/**
* Assert the response content match a previous taken snapshot.
* If the snapshot doesn't exists on the first run it gets
* created and the test is marked as incomplete.
*/
private function seeSnapshot()
{
$testName = debug_backtrace()[1]['function'];
$filename = "snapshots/{$testName}.json";
if (file_exists($filename)) {
$snapshot = file_get_contents($filename);
$this->seeJson(json_decode($snapshot, true));
} else {
file_put_contents($filename, $this->response->getContent());
$this->markTestIncomplete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment