@@ -209,7 +209,10 @@ public function it_can_mismatch_a_file_snapshot()
209209 {
210210 $ mockTrait = $ this ->getMatchesSnapshotMock ();
211211
212- $ this ->expectFail ($ mockTrait );
212+ $ this ->expectFail (
213+ $ mockTrait ,
214+ 'File did not match snapshot (MatchesSnapshotTest__it_can_mismatch_a_file_snapshot__1.jpg) '
215+ );
213216
214217 $ mockTrait ->assertMatchesFileSnapshot (__DIR__ .'/stubs/test_files/troubled_man.jpg ' );
215218 }
@@ -219,7 +222,10 @@ public function it_can_mismatch_a_file_snapshot_with_a_different_extension()
219222 {
220223 $ mockTrait = $ this ->getMatchesSnapshotMock ();
221224
222- $ this ->expectFail ($ mockTrait );
225+ $ this ->expectFail (
226+ $ mockTrait ,
227+ 'File did not match the snapshot file extension (expected: jpg, was: png) '
228+ );
223229
224230 $ mockTrait ->assertMatchesFileSnapshot (__DIR__ .'/stubs/test_files/no_man.png ' );
225231 }
@@ -229,10 +235,15 @@ public function it_needs_a_file_extension_to_do_a_file_snapshot_assertion()
229235 {
230236 $ mockTrait = $ this ->getMatchesSnapshotMock ();
231237
232- $ this ->expectFail ($ mockTrait );
233-
234238 $ filePath = __DIR__ .'/stubs/test_files/file_without_extension ' ;
235239
240+ $ this ->expectFail (
241+ $ mockTrait ,
242+ 'Unable to make a file snapshot, file does not have a file extension ' .
243+ "( $ filePath) "
244+ );
245+
246+
236247 $ this ->assertFileExists ($ filePath );
237248
238249 $ mockTrait ->assertMatchesFileSnapshot ($ filePath );
@@ -243,7 +254,10 @@ public function it_persists_the_failed_file_after_mismatching_a_file_snapshot()
243254 {
244255 $ mockTrait = $ this ->getMatchesSnapshotMock ();
245256
246- $ this ->expectFail ($ mockTrait );
257+ $ this ->expectFail (
258+ $ mockTrait ,
259+ 'File did not match snapshot (MatchesSnapshotTest__it_persists_the_failed_file_after_mismatching_a_file_snapshot__1.jpg) '
260+ );
247261
248262 $ mismatchedFile = __DIR__ .'/stubs/test_files/troubled_man.jpg ' ;
249263
@@ -392,11 +406,15 @@ private function expectIncompleteMatchesSnapshotTest(MockObject $matchesSnapshot
392406 $ matchesSnapshotMock ->markTestIncompleteIfSnapshotsHaveChanged ();
393407 }
394408
395- private function expectFail (MockObject $ matchesSnapshotMock )
409+ private function expectFail (MockObject $ matchesSnapshotMock, string $ message )
396410 {
411+ $ this ->expectException (AssertionFailedError::class);
412+
397413 $ matchesSnapshotMock
398414 ->expects ($ this ->once ())
399- ->method ('fail ' );
415+ ->method ('fail ' )
416+ ->with ($ message )
417+ ->willThrowException (new AssertionFailedError ());
400418 }
401419
402420 private function expectFailedMatchesSnapshotTest ()
0 commit comments