@@ -292,6 +292,23 @@ public function it_deletes_the_persisted_failed_file_before_a_file_snapshot_asse
292
292
$this->assertFileDoesNotExist($persistedFailedFile);
293
293
}
294
294
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
+
295
312
/** @test */
296
313
public function it_can_update_a_string_snapshot()
297
314
{
@@ -447,7 +464,7 @@ private function expectFailedMatchesSnapshotTest()
447
464
/**
448
465
* @return \PHPUnit\Framework\MockObject\MockObject|\Spatie\Snapshots\MatchesSnapshots
449
466
*/
450
- private function getMatchesSnapshotMock(): MockObject
467
+ private function getMatchesSnapshotMock(bool $mockGetSnapshotId = true ): MockObject
451
468
{
452
469
$mockMethods = [
453
470
'markTestIncomplete',
@@ -468,10 +485,12 @@ private function getMatchesSnapshotMock(): MockObject
468
485
$mockMethods
469
486
);
470
487
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
+ }
475
494
476
495
$matchesSnapshotMock
477
496
->expects($this->any())
0 commit comments