-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Assert::snapshot() and make Snapshot an instantiable representati…
…on of a single snapshot
- Loading branch information
Showing
10 changed files
with
159 additions
and
106 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
use Tester\AssertException; | ||
use Tester\Snapshot; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
Snapshot::$snapshotDir = __DIR__ . '/fixtures'; | ||
|
||
Assert::snapshot('existingSnapshot', ['answer' => 42]); | ||
|
||
Assert::exception(function () { | ||
Assert::snapshot('invalid / name', ['answer' => 42]); | ||
}, \Exception::class, "Invalid snapshot name 'invalid / name'. Only alphanumeric characters, dash and underscore are allowed."); | ||
|
||
Assert::exception(function () { | ||
Assert::snapshot('existingSnapshot', ['answer' => 42]); | ||
}, \Exception::class, "Snapshot 'existingSnapshot' was already asserted, please use a different name."); | ||
|
||
Assert::exception(function () { | ||
Assert::snapshot('anotherSnapshot', ['answer' => 43]); | ||
}, AssertException::class, "%a% should be %a% in snapshot 'anotherSnapshot'"); | ||
|
||
Assert::exception(function () { | ||
Assert::snapshot('nonExistingSnapshot', 'value'); | ||
}, AssertException::class, "Missing snapshot 'nonExistingSnapshot', use --update-snapshots option to generate it."); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
use Tester\Environment; | ||
use Tester\Helpers; | ||
use Tester\Snapshot; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
putenv(Environment::UPDATE_SNAPSHOTS . '=1'); | ||
Snapshot::$snapshotDir = __DIR__ . '/snapshots'; | ||
Helpers::purge(Snapshot::$snapshotDir); | ||
|
||
// newly created | ||
|
||
Assert::false(file_exists(Snapshot::$snapshotDir . '/Assert.snapshot.update.newSnapshot.phps')); | ||
Assert::snapshot('newSnapshot', ['answer' => 42]); | ||
Assert::true(file_exists(Snapshot::$snapshotDir . '/Assert.snapshot.update.newSnapshot.phps')); | ||
Assert::contains('42', file_get_contents(Snapshot::$snapshotDir . '/Assert.snapshot.update.newSnapshot.phps')); | ||
|
||
// existing | ||
|
||
file_put_contents( | ||
Snapshot::$snapshotDir . '/Assert.snapshot.update.updatedSnapshot.phps', | ||
'<?php return array(\'answer\' => 43);' . PHP_EOL | ||
); | ||
|
||
Assert::true(file_exists(Snapshot::$snapshotDir . '/Assert.snapshot.update.updatedSnapshot.phps')); | ||
Assert::snapshot('updatedSnapshot', ['answer' => 42]); | ||
Assert::true(file_exists(Snapshot::$snapshotDir . '/Assert.snapshot.update.updatedSnapshot.phps')); | ||
Assert::contains('42', file_get_contents(Snapshot::$snapshotDir . '/Assert.snapshot.update.updatedSnapshot.phps')); | ||
|
||
// Snapshot::$updatedSnapshots | ||
|
||
Assert::same([ | ||
Snapshot::$snapshotDir . DIRECTORY_SEPARATOR . 'Assert.snapshot.update.newSnapshot.phps', | ||
Snapshot::$snapshotDir . DIRECTORY_SEPARATOR . 'Assert.snapshot.update.updatedSnapshot.phps', | ||
], Snapshot::$updatedSnapshots); | ||
|
||
// reset the env variable so that the test does not fail due to updated snapshots | ||
putenv(Environment::UPDATE_SNAPSHOTS . '=0'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return ['answer' => 42]; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
|
||
use Tester\Snapshot; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
Snapshot::match('snapshot value', 'snapshot'); | ||
Assert::snapshot('snapshot', 'snapshot value'); |