Last active
January 4, 2019 07:09
-
-
Save micc83/3894ea89e209b60a88bbba3870ae84ed to your computer and use it in GitHub Desktop.
PHPUnit Assertion that asserts the response content match a previous taken snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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