Skip to content

Commit

Permalink
[DX] Cleanup AbstractRectorTestCase (#2882)
Browse files Browse the repository at this point in the history
* remove direct symplify/smart-file-system, still transitional

* use one place of temp directory path knowledge

* comm
  • Loading branch information
TomasVotruba committed Sep 1, 2022
1 parent 36ac530 commit c6c1026
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"symplify/easy-parallel": "^11.1",
"symplify/package-builder": "dev-main",
"symplify/rule-doc-generator-contracts": "^11.1",
"symplify/smart-file-system": "^11.1",
"webmozart/assert": "^1.11"
},
"require-dev": {
Expand Down
7 changes: 6 additions & 1 deletion packages/Testing/Fixture/FixtureTempFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ final class FixtureTempFileDumper
public static function dump(string $fileContents, string $suffix = 'php'): string
{
// the "php" suffix is important, because that will hook into \Rector\Core\Application\FileProcessor\PhpFileProcessor
$temporaryFileName = sys_get_temp_dir() . self::TEMP_FIXTURE_DIRECTORY . '/' . md5($fileContents) . '.' . $suffix;
$temporaryFileName = self::getTempDirectory() . '/' . md5($fileContents) . '.' . $suffix;
FileSystem::write($temporaryFileName, $fileContents);

return $temporaryFileName;
}

public static function getTempDirectory(): string
{
return sys_get_temp_dir() . self::TEMP_FIXTURE_DIRECTORY;
}
}
9 changes: 2 additions & 7 deletions packages/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ protected function doTestFileInfo(SmartFileInfo $fixtureFileInfo): void

protected function getFixtureTempDirectory(): string
{
return sys_get_temp_dir() . FixtureTempFileDumper::TEMP_FIXTURE_DIRECTORY;
return FixtureTempFileDumper::getTempDirectory();
}

private function resolveExpectedContents(string $filePath): string
{
$contents = FileSystem::read($filePath);

// make sure we don't get a diff in which every line is different (because of differences in EOL)
return $this->normalizeNewlines($contents);
return str_replace("\r\n", "\n", $contents);
}

private function resolveOriginalFixtureFileSuffix(string $filePath): string
Expand Down Expand Up @@ -205,11 +205,6 @@ private function doTestFileMatchesExpectedContent(
}
}

private function normalizeNewlines(string $string): string
{
return str_replace("\r\n", "\n", $string);
}

private function processFilePath(string $filePath): string
{
$this->dynamicSourceLocatorProvider->setFilePath($filePath);
Expand Down
2 changes: 1 addition & 1 deletion packages/Testing/PHPUnit/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function bootFromConfigFiles(array $configFiles): void
protected function getService(string $type): object
{
if (self::$currentContainer === null) {
throw new ShouldNotHappenException('First, create container with "bootWithConfigFileInfos([...])"');
throw new ShouldNotHappenException('First, create container with "boot()" or "bootWithConfigFileInfos([...])"');
}

$object = self::$currentContainer->get($type);
Expand Down

0 comments on commit c6c1026

Please sign in to comment.