1515use Rector \Util \FileHasher ;
1616use Rector \ValueObject \Application \File ;
1717use Rector \ValueObject \Configuration ;
18+ use Rector \ValueObject \FileProcessResult ;
1819use Rector \ValueObject \Reporting \FileDiff ;
1920use Symfony \Component \Filesystem \Filesystem ;
2021
@@ -68,19 +69,37 @@ public function testSaveLoadRoundTrip(): void
6869 $ this ->assertNull ($ this ->dryRunDiffCache ->load ($ file , $ configuration ));
6970
7071 $ this ->fileDependencyCollector ->record ($ this ->sourceFilePath , $ this ->dependencyFilePath );
71- $ this ->dryRunDiffCache ->save ($ file , $ configuration , $ this ->createFileDiff ());
72+ $ this ->dryRunDiffCache ->save ($ file , $ configuration , $ this ->createFileDiff (), true );
7273
73- $ loadedFileDiff = $ this ->dryRunDiffCache ->load ($ file , $ configuration );
74+ $ cachedFileProcessResult = $ this ->dryRunDiffCache ->load ($ file , $ configuration );
75+ $ this ->assertInstanceOf (FileProcessResult::class, $ cachedFileProcessResult );
76+ $ this ->assertTrue ($ cachedFileProcessResult ->hasChanged ());
77+
78+ $ loadedFileDiff = $ cachedFileProcessResult ->getFileDiff ();
7479 $ this ->assertInstanceOf (FileDiff::class, $ loadedFileDiff );
7580 $ this ->assertSame ('some diff ' , $ loadedFileDiff ->getDiff ());
7681 $ this ->assertSame ([RemoveUnusedPrivateMethodRector::class], $ loadedFileDiff ->getRectorClasses ());
7782 }
7883
84+ public function testReplayKeepsUnchangedFlag (): void
85+ {
86+ $ file = $ this ->createFile ();
87+ $ configuration = new Configuration (isDryRun: true );
88+
89+ // a rule can report line changes while the printed content stays identical
90+ $ this ->fileDependencyCollector ->record ($ this ->sourceFilePath , $ this ->dependencyFilePath );
91+ $ this ->dryRunDiffCache ->save ($ file , $ configuration , $ this ->createFileDiff (), false );
92+
93+ $ cachedFileProcessResult = $ this ->dryRunDiffCache ->load ($ file , $ configuration );
94+ $ this ->assertInstanceOf (FileProcessResult::class, $ cachedFileProcessResult );
95+ $ this ->assertFalse ($ cachedFileProcessResult ->hasChanged ());
96+ }
97+
7998 public function testChangedOwnContentInvalidates (): void
8099 {
81100 $ file = $ this ->createFile ();
82101 $ configuration = new Configuration (isDryRun: true );
83- $ this ->dryRunDiffCache ->save ($ file , $ configuration , $ this ->createFileDiff ());
102+ $ this ->dryRunDiffCache ->save ($ file , $ configuration , $ this ->createFileDiff (), true );
84103
85104 $ changedFile = new File ($ this ->sourceFilePath , "<?php \n\nclass Source \n{ \n public int \$added; \n} \n" );
86105 $ this ->assertNull ($ this ->dryRunDiffCache ->load ($ changedFile , $ configuration ));
@@ -92,8 +111,8 @@ public function testChangedDependencyInvalidates(): void
92111 $ configuration = new Configuration (isDryRun: true );
93112
94113 $ this ->fileDependencyCollector ->record ($ this ->sourceFilePath , $ this ->dependencyFilePath );
95- $ this ->dryRunDiffCache ->save ($ file , $ configuration , $ this ->createFileDiff ());
96- $ this ->assertInstanceOf (FileDiff ::class, $ this ->dryRunDiffCache ->load ($ file , $ configuration ));
114+ $ this ->dryRunDiffCache ->save ($ file , $ configuration , $ this ->createFileDiff (), true );
115+ $ this ->assertInstanceOf (FileProcessResult ::class, $ this ->dryRunDiffCache ->load ($ file , $ configuration ));
97116
98117 (new Filesystem ())->dumpFile (
99118 $ this ->dependencyFilePath ,
@@ -121,7 +140,8 @@ public function testNoDiffsConfigurationDoesNotCrossReplay(): void
121140 $ this ->dryRunDiffCache ->save (
122141 $ file ,
123142 new Configuration (isDryRun: true , showDiffs: false ),
124- $ this ->createFileDiff ()
143+ $ this ->createFileDiff (),
144+ true
125145 );
126146
127147 $ this ->assertNull ($ this ->dryRunDiffCache ->load ($ file , new Configuration (isDryRun: true , showDiffs: true )));
0 commit comments