Skip to content

Commit

Permalink
[Testing] Reduce IO on AbstractRectorTestCase take 2 (#3671)
Browse files Browse the repository at this point in the history
* [Testing] Reduce IO on AbstractRectorTestCase take 2

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Apr 23, 2023
1 parent c6d11cd commit 092fb22
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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);
}

private function includePreloadFilesAndScoperAutoload(): void
Expand All @@ -146,12 +146,13 @@ private function includePreloadFilesAndScoperAutoload(): void

private function doTestFileMatchesExpectedContent(
string $originalFilePath,
string $inputFileContents,
string $expectedFileContents,
string $fixtureFilePath
): void {
$this->parameterProvider->changeParameter(Option::SOURCE, [$originalFilePath]);

$changedContent = $this->processFilePath($originalFilePath);
$changedContent = $this->processFilePath($originalFilePath, $inputFileContents);

// file is removed, we cannot compare it
if ($this->removedAndAddedFilesCollector->isFileRemoved($originalFilePath)) {
Expand All @@ -171,7 +172,7 @@ private function doTestFileMatchesExpectedContent(
}
}

private function processFilePath(string $filePath): string
private function processFilePath(string $filePath, string $inputFileContents): string
{
$this->dynamicSourceLocatorProvider->setFilePath($filePath);

Expand All @@ -184,7 +185,7 @@ private function processFilePath(string $filePath): string
$configurationFactory = $this->getService(ConfigurationFactory::class);
$configuration = $configurationFactory->createForTests([$filePath]);

$file = new File($filePath, FileSystem::read($filePath));
$file = new File($filePath, $inputFileContents);
$this->applicationFileProcessor->processFiles([$file], $configuration);

return $file->getFileContent();
Expand Down

0 comments on commit 092fb22

Please sign in to comment.