Skip to content

Commit

Permalink
[Performance] Reduce repetitive FileSystem::read() on AbstractRectorT…
Browse files Browse the repository at this point in the history
…estCase (#5511)
  • Loading branch information
samsonasik committed Jan 28, 2024
1 parent 63fbf41 commit b107a16
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function doTestFile(string $fixtureFilePath): void
// write temp file
FileSystem::write($inputFilePath, $inputFileContents);

$this->doTestFileMatchesExpectedContent($inputFilePath, $expectedFileContents, $fixtureFilePath);
$this->doTestFileMatchesExpectedContent($inputFilePath, $inputFileContents, $expectedFileContents, $fixtureFilePath);
}

protected function forgetRectorsRulesAndCollectors(): void
Expand Down Expand Up @@ -210,14 +210,12 @@ private function includePreloadFilesAndScoperAutoload(): void

private function doTestFileMatchesExpectedContent(
string $originalFilePath,
string $inputFileContents,
string $expectedFileContents,
string $fixtureFilePath
): void {
SimpleParameterProvider::setParameter(Option::SOURCE, [$originalFilePath]);

// the original file content must be loaded first
$originalFileContent = FileSystem::read($originalFilePath);

// the file is now changed (if any rule matches)
$rectorTestResult = $this->processFilePath($originalFilePath);

Expand All @@ -239,7 +237,7 @@ private function doTestFileMatchesExpectedContent(
try {
$this->assertSame($expectedFileContents, $changedContents, $failureMessage);
} catch (ExpectationFailedException) {
FixtureFileUpdater::updateFixtureContent($originalFileContent, $changedContents, $fixtureFilePath);
FixtureFileUpdater::updateFixtureContent($inputFileContents, $changedContents, $fixtureFilePath);

// if not exact match, check the regex version (useful for generated hashes/uuids in the code)
$this->assertStringMatchesFormat($expectedFileContents, $changedContents, $failureMessage);
Expand Down

0 comments on commit b107a16

Please sign in to comment.