@@ -292,6 +292,23 @@ public function it_deletes_the_persisted_failed_file_before_a_file_snapshot_asse
292292 $ this ->assertFileDoesNotExist ($ persistedFailedFile );
293293 }
294294
295+ /** @test */
296+ public function it_cleans_filenames_on_file_snapshot ()
297+ {
298+ $ mockTrait = $ this ->getMatchesSnapshotMock (false );
299+ $ mockTrait
300+ ->expects ($ this ->any ())
301+ ->method ('getSnapshotId ' )
302+ ->willReturn ('MatchesSnapshotTest__it_cleans_filenames_on_file_snapshot with dataset "Empty"__1 ' );
303+
304+ $ this ->expectFail (
305+ $ mockTrait ,
306+ 'File did not match snapshot (MatchesSnapshotTest__it_cleans_filenames_on_file_snapshot with dataset Empty__1.jpg) '
307+ );
308+
309+ $ mockTrait ->assertMatchesFileSnapshot (__DIR__ .'/stubs/test_files/troubled_man.jpg ' );
310+ }
311+
295312 /** @test */
296313 public function it_can_update_a_string_snapshot ()
297314 {
@@ -447,7 +464,7 @@ private function expectFailedMatchesSnapshotTest()
447464 /**
448465 * @return \PHPUnit\Framework\MockObject\MockObject|\Spatie\Snapshots\MatchesSnapshots
449466 */
450- private function getMatchesSnapshotMock (): MockObject
467+ private function getMatchesSnapshotMock (bool $ mockGetSnapshotId = true ): MockObject
451468 {
452469 $ mockMethods = [
453470 'markTestIncomplete ' ,
@@ -468,10 +485,12 @@ private function getMatchesSnapshotMock(): MockObject
468485 $ mockMethods
469486 );
470487
471- $ matchesSnapshotMock
472- ->expects ($ this ->any ())
473- ->method ('getSnapshotId ' )
474- ->willReturn ('MatchesSnapshotTest__ ' .$ this ->getName ().'__1 ' );
488+ if ($ mockGetSnapshotId ) {
489+ $ matchesSnapshotMock
490+ ->expects ($ this ->any ())
491+ ->method ('getSnapshotId ' )
492+ ->willReturn ('MatchesSnapshotTest__ ' .$ this ->getName ().'__1 ' );
493+ }
475494
476495 $ matchesSnapshotMock
477496 ->expects ($ this ->any ())
0 commit comments