From 94d3b1da7a42492d3a792ed002f146b6472c9231 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 16 Jul 2021 09:13:40 +0200 Subject: [PATCH] support assertFileEquals() normalizing --- .../ValueObject/AddedFileWithContent.php | 19 ------- .../PHPUnit/AbstractRectorTestCase.php | 27 +++++----- .../PHPUnit/PlatformAgnosticAssertions.php | 53 +++++++++++++------ .../SensitiveHereNowDocRectorTest.php | 3 ++ .../TypeDeclaration/TypeNormalizerTest.php | 10 ++-- rules/PSR4/FileRelocationResolver.php | 3 +- .../ClassWithPublicPropertiesFactoryTest.php | 2 + 7 files changed, 61 insertions(+), 56 deletions(-) diff --git a/packages/FileSystemRector/ValueObject/AddedFileWithContent.php b/packages/FileSystemRector/ValueObject/AddedFileWithContent.php index 16c7981cf72..4c4dc91776a 100644 --- a/packages/FileSystemRector/ValueObject/AddedFileWithContent.php +++ b/packages/FileSystemRector/ValueObject/AddedFileWithContent.php @@ -18,7 +18,6 @@ public function __construct( } } -<<<<<<< HEAD public function getRealPath(): string { $realpath = realpath($this->filePath); @@ -27,24 +26,6 @@ public function getRealPath(): string } return $realpath; -======= - /** - * @return string - */ - public function getRealPath() - { -<<<<<<< HEAD - return realpath($this->filePath); ->>>>>>> d5ea8a664 (apply PlatformAgnosticAssertions on MoveValueObjectsToValueObjectDirectoryRectorTest) -======= - $realpath = realpath($this->filePath); - - if ($realpath === false) { - throw new ShouldNotHappenException(); - } - - return $realpath; ->>>>>>> c169f9af3 (eleminate false-return type from AddedFileWithContent::getRealPath()) } public function getFilePath(): string diff --git a/packages/Testing/PHPUnit/AbstractRectorTestCase.php b/packages/Testing/PHPUnit/AbstractRectorTestCase.php index 5213e1697b5..ddb9bcdaffc 100644 --- a/packages/Testing/PHPUnit/AbstractRectorTestCase.php +++ b/packages/Testing/PHPUnit/AbstractRectorTestCase.php @@ -5,7 +5,6 @@ namespace Rector\Testing\PHPUnit; use Iterator; -use Nette\Utils\Strings; use PHPStan\Analyser\NodeScopeResolver; use PHPUnit\Framework\ExpectationFailedException; use Psr\Container\ContainerInterface; @@ -71,6 +70,18 @@ protected function setUp(): void $bootstrapFilesIncluder->includeBootstrapFiles(); } + protected function tearDown(): void + { + unset( + $this->applicationFileProcessor, + $this->parameterProvider, + $this->dynamicSourceLocatorProvider, + $this->removedAndAddedFilesCollector, + $this->originalTempFileInfo, + ); + gc_collect_cycles(); + } + /** * @return Iterator */ @@ -139,7 +150,7 @@ private function doTestFileMatchesExpectedContent( private function normalizeNewlines(string $string): string { - return Strings::replace($string, '#\r\n|\r|\n#', "\n"); + return str_replace("\r\n", "\n", $string); } private function processFileInfo(SmartFileInfo $fileInfo): string @@ -160,16 +171,4 @@ private function processFileInfo(SmartFileInfo $fileInfo): string return $file->getFileContent(); } - - protected function tearDown(): void - { - unset( - $this->applicationFileProcessor, - $this->parameterProvider, - $this->dynamicSourceLocatorProvider, - $this->removedAndAddedFilesCollector, - $this->originalTempFileInfo, - ); - gc_collect_cycles(); - } } diff --git a/packages/Testing/PHPUnit/PlatformAgnosticAssertions.php b/packages/Testing/PHPUnit/PlatformAgnosticAssertions.php index 5549cbe9382..19bc710a05a 100644 --- a/packages/Testing/PHPUnit/PlatformAgnosticAssertions.php +++ b/packages/Testing/PHPUnit/PlatformAgnosticAssertions.php @@ -1,22 +1,22 @@ typeNormalizer = $this->getService(TypeNormalizer::class); } + protected function tearDown(): void + { + unset($this->typeNormalizer); + } + /** * @dataProvider provideDataNormalizeArrayOfUnionToUnionArray() */ @@ -48,9 +53,4 @@ public function provideDataNormalizeArrayOfUnionToUnionArray(): Iterator $evenMoreNestedArrayType = new ArrayType(new MixedType(), $moreNestedArrayType); yield [$evenMoreNestedArrayType, 'int[][][]|string[][][]']; } - - protected function tearDown(): void - { - unset($this->typeNormalizer); - } } diff --git a/rules/PSR4/FileRelocationResolver.php b/rules/PSR4/FileRelocationResolver.php index 545133dc3ed..64081a73bf6 100644 --- a/rules/PSR4/FileRelocationResolver.php +++ b/rules/PSR4/FileRelocationResolver.php @@ -180,7 +180,8 @@ private function replaceRelativeFilePathsWithBeforeAfter( return implode(DIRECTORY_SEPARATOR, $relativeFilePathParts); } - private function normalizeDirectorySeparator(string $path):string { + private function normalizeDirectorySeparator(string $path): string + { return str_replace('/', DIRECTORY_SEPARATOR, $path); } } diff --git a/tests/NodeFactory/ClassWithPublicPropertiesFactory/ClassWithPublicPropertiesFactoryTest.php b/tests/NodeFactory/ClassWithPublicPropertiesFactory/ClassWithPublicPropertiesFactoryTest.php index 216b8a96b21..bcb165508cd 100644 --- a/tests/NodeFactory/ClassWithPublicPropertiesFactory/ClassWithPublicPropertiesFactoryTest.php +++ b/tests/NodeFactory/ClassWithPublicPropertiesFactory/ClassWithPublicPropertiesFactoryTest.php @@ -34,6 +34,8 @@ protected function setUp(): void public function test(SmartFileInfo $fixtureFileInfo): void { $contents = $fixtureFileInfo->getContents(); + // normalize for windows compat + $contents = str_replace("\r\n", "\n", $contents); [$content, $expected] = explode("-----\n", $contents, 2); $classSettings = Json::decode($content, Json::FORCE_ARRAY);