diff --git a/packages/Testing/PHPUnit/AbstractRectorTestCase.php b/packages/Testing/PHPUnit/AbstractRectorTestCase.php index 7bb97ede0a4..a367325d78f 100644 --- a/packages/Testing/PHPUnit/AbstractRectorTestCase.php +++ b/packages/Testing/PHPUnit/AbstractRectorTestCase.php @@ -20,6 +20,7 @@ use Rector\Core\Contract\Rector\RectorInterface; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser; +use Rector\Core\Provider\CurrentFileProvider; use Rector\Core\Rector\AbstractRector; use Rector\Core\Util\Reflection\PrivatesAccessor; use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider; @@ -41,6 +42,8 @@ abstract class AbstractRectorTestCase extends AbstractLazyTestCase implements Re */ private static array $cacheByRuleAndConfig = []; + private CurrentFileProvider $currentFileProvider; + /** * Restore default parameters */ @@ -112,6 +115,8 @@ protected function setUp(): void /** @var BootstrapFilesIncluder $bootstrapFilesIncluder */ $bootstrapFilesIncluder = $this->make(BootstrapFilesIncluder::class); $bootstrapFilesIncluder->includeBootstrapFiles(); + + $this->currentFileProvider = $this->make(CurrentFileProvider::class); } protected function tearDown(): void @@ -225,8 +230,8 @@ private function doTestFileMatchesExpectedContent( ): void { SimpleParameterProvider::setParameter(Option::SOURCE, [$originalFilePath]); - $originalContents = FileSystem::read($originalFilePath); $changedContent = $this->processFilePath($originalFilePath); + $originalFileContent = $this->currentFileProvider->getFile()->getOriginalFileContent(); $fixtureFilename = basename($fixtureFilePath); $failureMessage = sprintf('Failed on fixture file "%s"', $fixtureFilename); @@ -234,7 +239,7 @@ private function doTestFileMatchesExpectedContent( try { $this->assertSame($expectedFileContents, $changedContent, $failureMessage); } catch (ExpectationFailedException) { - FixtureFileUpdater::updateFixtureContent($originalContents, $changedContent, $fixtureFilePath); + FixtureFileUpdater::updateFixtureContent($originalFileContent, $changedContent, $fixtureFilePath); // if not exact match, check the regex version (useful for generated hashes/uuids in the code) $this->assertStringMatchesFormat($expectedFileContents, $changedContent, $failureMessage); @@ -256,7 +261,7 @@ private function processFilePath(string $filePath): string $this->applicationFileProcessor->processFiles([$filePath], $configuration); - return FileSystem::read($filePath); + return $this->currentFileProvider->getFile()->getFileContent(); } private function createInputFilePath(string $fixtureFilePath): string