Skip to content

Commit f052666

Browse files
Merge pull request #31 from SjorsO/master
fix file hash snapshots
2 parents d3b4a59 + 672c9a2 commit f052666

9 files changed

+22
-67
lines changed

src/Drivers/FileHashDriver.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/MatchesSnapshots.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPUnit_Framework_ExpectationFailedException;
77
use ReflectionClass;
88
use ReflectionObject;
9-
use Spatie\Snapshots\Drivers\FileHashDriver;
109
use Spatie\Snapshots\Drivers\JsonDriver;
1110
use Spatie\Snapshots\Drivers\VarDriver;
1211
use Spatie\Snapshots\Drivers\XmlDriver;
@@ -45,7 +44,7 @@ public function assertMatchesFileHashSnapshot($filePath)
4544

4645
$actual = sha1_file($filePath);
4746

48-
$this->assertMatchesSnapshot($actual, new FileHashDriver());
47+
$this->assertMatchesSnapshot($actual);
4948
}
5049

5150
/**

tests/Integration/MatchesSnapshotTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ public function it_can_match_an_existing_json_snapshot()
9292
$mockTrait->assertMatchesJsonSnapshot('{"foo":"foo","bar":"bar","baz":"baz"}');
9393
}
9494

95+
/** @test */
96+
public function it_can_match_an_existing_file_hash_snapshot()
97+
{
98+
$mockTrait = $this->getMatchesSnapshotMock();
99+
100+
$mockTrait->assertMatchesFileHashSnapshot(__DIR__.'/stubs/example_snapshots/snapshot.json');
101+
}
102+
95103
/** @test */
96104
public function it_can_mismatch_a_string_snapshot()
97105
{
@@ -122,6 +130,16 @@ public function it_can_mismatch_a_json_snapshot()
122130
$mockTrait->assertMatchesJsonSnapshot('{"foo":"baz","bar":"baz","baz":"foo"}');
123131
}
124132

133+
/** @test */
134+
public function it_can_mismatch_a_file_hash_snapshot()
135+
{
136+
$mockTrait = $this->getMatchesSnapshotMock();
137+
138+
$this->expectFailedMatchesSnapshotTest();
139+
140+
$mockTrait->assertMatchesFileHashSnapshot(__DIR__.'/stubs/example_snapshots/snapshot.json');
141+
}
142+
125143
/** @test */
126144
public function it_can_update_a_string_snapshot()
127145
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return 'f558f8149e33fba2916877b2d3de4a42ebd544b4';

tests/Integration/stubs/__snapshots__/AssertionTest__can_match_a_file_hash_snapshot__1.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return 'f558f8149e33fba2916877b2d3de4a42ebd544b4';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return 'wrong_hash_3fba2916877b2d3de4a42ebd544b4';

tests/Unit/Drivers/FileHashDriverTest.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/Unit/Drivers/files/example-file.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)