From f2eaeec59e95b5a4f8d1027f58f36ee3635cfab4 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 19 Feb 2024 16:29:19 +0100 Subject: [PATCH] Fix --- src/Report/Reporter/TextReporter.php | 8 +- tests/Binary/TwigCsFixerTest.php | 6 +- tests/Command/TwigCsFixerCommandTest.php | 88 ++++++++++++------- tests/Config/ConfigResolverTest.php | 21 +++-- tests/FileTestCase.php | 4 +- .../Reporter/CheckstyleReporterTest.php | 35 +++++--- tests/Report/Reporter/GithubReporterTest.php | 27 +++--- tests/Report/Reporter/JUnitReporterTest.php | 52 ++++++----- tests/Report/Reporter/NullReporterTest.php | 3 +- tests/Report/Reporter/TextReporterTest.php | 45 ++++++---- tests/Token/Tokenizer/TokenizerTest.php | 4 +- 11 files changed, 177 insertions(+), 116 deletions(-) diff --git a/src/Report/Reporter/TextReporter.php b/src/Report/Reporter/TextReporter.php index 85109403..df904cff 100644 --- a/src/Report/Reporter/TextReporter.php +++ b/src/Report/Reporter/TextReporter.php @@ -59,7 +59,7 @@ public function display( $formattedText[] = sprintf( self::ERROR_LINE_FORMAT, $no, - wordwrap($code, self::ERROR_LINE_WIDTH) + wordwrap($code, self::ERROR_LINE_WIDTH, \PHP_EOL) ); if ($no === $violation->getLine()) { @@ -75,7 +75,7 @@ public function display( $messageLevel = Violation::getLevelAsString($violation->getLevel()); $rows[] = [ new TableCell(sprintf('%s', $messageLevel)), - implode("\n", $formattedText), + implode(\PHP_EOL, $formattedText), ]; } @@ -106,7 +106,7 @@ public function display( */ private function getContext(string $template, int $line): array { - $lines = explode("\n", $template); + $lines = explode(\PHP_EOL, $template); $position = max(0, $line - 2); $max = min(\count($lines), $line + 1); @@ -128,7 +128,7 @@ private function formatErrorMessage(Violation $message, bool $debug): string return sprintf( sprintf('%s', self::ERROR_LINE_FORMAT), self::ERROR_CURSOR_CHAR, - wordwrap($message->getDebugMessage($debug), self::ERROR_LINE_WIDTH) + wordwrap($message->getDebugMessage($debug), self::ERROR_LINE_WIDTH, \PHP_EOL) ); } } diff --git a/tests/Binary/TwigCsFixerTest.php b/tests/Binary/TwigCsFixerTest.php index 749c5b47..e645383c 100644 --- a/tests/Binary/TwigCsFixerTest.php +++ b/tests/Binary/TwigCsFixerTest.php @@ -11,7 +11,11 @@ final class TwigCsFixerTest extends FileTestCase { public function testBinary(): void { - $process = Process::fromShellCommandline(sprintf('%s lint Fixtures', __DIR__.'/../../bin/twig-cs-fixer')); + $slash = \DIRECTORY_SEPARATOR; + $process = Process::fromShellCommandline(sprintf( + '%s lint Fixtures', + __DIR__.$slash.'..'.$slash.'..'.$slash.'bin'.$slash.'twig-cs-fixer' + )); static::assertSame(0, $process->run()); } diff --git a/tests/Command/TwigCsFixerCommandTest.php b/tests/Command/TwigCsFixerCommandTest.php index 191d8e76..b1474a70 100644 --- a/tests/Command/TwigCsFixerCommandTest.php +++ b/tests/Command/TwigCsFixerCommandTest.php @@ -22,7 +22,7 @@ public function testExecuteWithSuccess(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures/file.twig')], + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'file.twig')], ]); static::assertStringContainsString( @@ -38,7 +38,7 @@ public function testExecuteWithOptionFix(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures/file.twig')], + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'file.twig')], '--fix' => true, ]); @@ -55,12 +55,18 @@ public function testExecuteWithReportErrors(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], ]); $display = $commandTester->getDisplay(); - static::assertStringContainsString('directory/subdirectory/file.twig', $display); - static::assertStringContainsString('directory/file.twig', $display); + static::assertStringContainsString( + 'directory'.\DIRECTORY_SEPARATOR.'subdirectory'.\DIRECTORY_SEPARATOR.'file.twig', + $display + ); + static::assertStringContainsString( + 'directory'.\DIRECTORY_SEPARATOR.'file.twig', + $display + ); static::assertStringNotContainsString('DelimiterSpacing.After', $display); static::assertStringContainsString( '[ERROR] Files linted: 3, notices: 0, warnings: 0, errors: 3', @@ -75,13 +81,19 @@ public function testExecuteWithReportErrorsAndDebug(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], '--debug' => true, ]); $display = $commandTester->getDisplay(); - static::assertStringContainsString('directory/subdirectory/file.twig', $display); - static::assertStringContainsString('directory/file.twig', $display); + static::assertStringContainsString( + 'directory'.\DIRECTORY_SEPARATOR.'subdirectory'.\DIRECTORY_SEPARATOR.'file.twig', + $display + ); + static::assertStringContainsString( + 'directory'.\DIRECTORY_SEPARATOR.'file.twig', + $display + ); static::assertStringContainsString('DelimiterSpacing.After', $display); static::assertStringContainsString( '[ERROR] Files linted: 3, notices: 0, warnings: 0, errors: 3', @@ -96,14 +108,20 @@ public function testExecuteWithReportErrorsFixed(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], '--fix' => true, ]); $display = $commandTester->getDisplay(); static::assertStringNotContainsString('Changed', $display); - static::assertStringNotContainsString('directory/subdirectory/file.twig', $display); - static::assertStringContainsString('directory/file.twig', $display); + static::assertStringNotContainsString( + 'directory'.\DIRECTORY_SEPARATOR.'subdirectory'.\DIRECTORY_SEPARATOR.'file.twig', + $display + ); + static::assertStringContainsString( + 'directory'.\DIRECTORY_SEPARATOR.'file.twig', + $display + ); static::assertStringContainsString( '[ERROR] Files linted: 3, notices: 0, warnings: 0, errors: 1', $display @@ -117,14 +135,20 @@ public function testExecuteWithReportErrorsFixedVerbose(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], '--fix' => true, ], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); $display = $commandTester->getDisplay(); static::assertStringContainsString('Changed', $display); - static::assertStringContainsString('directory/subdirectory/file.twig', $display); - static::assertStringContainsString('directory/file.twig', $display); + static::assertStringContainsString( + 'directory'.\DIRECTORY_SEPARATOR.'subdirectory'.\DIRECTORY_SEPARATOR.'file.twig', + $display + ); + static::assertStringContainsString( + 'directory'.\DIRECTORY_SEPARATOR.'file.twig', + $display + ); static::assertStringContainsString( '[ERROR] Files linted: 3, notices: 0, warnings: 0, errors: 1', $display @@ -138,7 +162,7 @@ public function testExecuteWithReportOption(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], '--no-cache' => true, // To avoid cache output '--report' => 'null', ]); @@ -153,8 +177,8 @@ public function testExecuteWithConfig(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], - '--config' => $this->getTmpPath(__DIR__.'/Fixtures/.twig-cs-fixer.php'), + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], + '--config' => $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'.twig-cs-fixer.php'), ]); static::assertStringContainsString( @@ -170,8 +194,8 @@ public function testExecuteWithError(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], - '--config' => $this->getTmpPath(__DIR__.'/Fixtures/.config-not-found.php'), + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], + '--config' => $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'.config-not-found.php'), ]); static::assertStringStartsWith('Error: Cannot find the config file', $commandTester->getDisplay()); @@ -184,7 +208,7 @@ public function testExecuteWithCacheByDefault(): void $commandTester = new CommandTester($command); - $path = $this->getTmpPath(__DIR__.'/Fixtures/file.twig'); + $path = $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'file.twig'); // Run two times to be sure to generate the cache. $commandTester->execute([ @@ -207,7 +231,7 @@ public function testExecuteWithCacheDisabled(): void $commandTester = new CommandTester($command); - $path = $this->getTmpPath(__DIR__.'/Fixtures/file.twig'); + $path = $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'file.twig'); // Run two times to be sure to generate the cache if we were using one. $commandTester->execute([ @@ -232,8 +256,8 @@ public function testExecuteWithCacheFile(): void $commandTester = new CommandTester($command); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], - '--config' => $this->getTmpPath(__DIR__.'/Fixtures/.twig-cs-fixer-with-cache.php'), + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], + '--config' => $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'.twig-cs-fixer-with-cache.php'), ]); // Result with no ruleset @@ -242,7 +266,7 @@ public function testExecuteWithCacheFile(): void $commandTester->getDisplay() ); - $cachePath = $this->getTmpPath(__DIR__.'/Fixtures/.twig-cs-fixer.cache'); + $cachePath = $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'.twig-cs-fixer.cache'); $cacheContent = file_get_contents($cachePath); static::assertNotFalse($cacheContent); @@ -250,8 +274,8 @@ public function testExecuteWithCacheFile(): void $hashes = CacheEncoder::fromJson($cacheContent)->getHashes(); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], - '--config' => $this->getTmpPath(__DIR__.'/Fixtures/.twig-cs-fixer-with-cache2.php'), + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], + '--config' => $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'.twig-cs-fixer-with-cache2.php'), ]); // Result with standard ruleset @@ -276,8 +300,8 @@ public function testExecuteWithCacheFile(): void file_put_contents($cachePath, CacheEncoder::toJson($cache)); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], - '--config' => $this->getTmpPath(__DIR__.'/Fixtures/.twig-cs-fixer-with-cache2.php'), + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], + '--config' => $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'.twig-cs-fixer-with-cache2.php'), ]); // We get the same result as with no ruleset because of the cache @@ -299,8 +323,8 @@ public function testExecuteWithCacheFile(): void file_put_contents($cachePath, CacheEncoder::toJson($newCache)); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], - '--config' => $this->getTmpPath(__DIR__.'/Fixtures/.twig-cs-fixer-with-cache2.php'), + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], + '--config' => $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'.twig-cs-fixer-with-cache2.php'), ]); // We get back the real result because of the different php version @@ -322,8 +346,8 @@ public function testExecuteWithCacheFile(): void file_put_contents($cachePath, CacheEncoder::toJson($newCache)); $commandTester->execute([ - 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], - '--config' => $this->getTmpPath(__DIR__.'/Fixtures/.twig-cs-fixer-with-cache2.php'), + 'paths' => [$this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')], + '--config' => $this->getTmpPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'.twig-cs-fixer-with-cache2.php'), ]); // We get back the real result because of the different fixer version diff --git a/tests/Config/ConfigResolverTest.php b/tests/Config/ConfigResolverTest.php index 41c16da1..c810c72f 100644 --- a/tests/Config/ConfigResolverTest.php +++ b/tests/Config/ConfigResolverTest.php @@ -119,7 +119,8 @@ public static function resolveFinderDataProvider(): iterable */ public function testConfigPathIsCorrectlyGenerated(string $configPath, string $path): void { - $configResolver = new ConfigResolver('/tmp/path/not/found'); + $slash = \DIRECTORY_SEPARATOR; + $configResolver = new ConfigResolver($slash.'tmp'.$slash.'path'.$slash.'not'.$slash.'found'); $this->expectExceptionMessage(sprintf('Cannot find the config file "%s".', $configPath)); $configResolver->resolveConfig([], $path); @@ -130,9 +131,11 @@ public function testConfigPathIsCorrectlyGenerated(string $configPath, string $p */ public static function configPathIsCorrectlyGeneratedDataProvider(): iterable { - yield ['/tmp/path/not/found/', '']; - yield ['/tmp/path/not/found/a', 'a']; - yield ['/tmp/path/not/found/../a', '../a']; + $slash = \DIRECTORY_SEPARATOR; + + yield [$slash.'tmp'.$slash.'path'.$slash.'not'.$slash.'found'.$slash, '']; + yield [$slash.'tmp'.$slash.'path'.$slash.'not'.$slash.'found'.$slash.'a', 'a']; + yield [$slash.'tmp'.$slash.'path'.$slash.'not'.$slash.'found'.$slash.'..'.$slash.'a', '..'.$slash.'a']; yield ['/a', '/a']; yield ['\\a', '\\a']; yield ['C:\WINDOWS', 'C:\WINDOWS']; @@ -173,19 +176,21 @@ public function testResolveCacheManager( */ public static function resolveCacheManagerDataProvider(): iterable { + $slash = \DIRECTORY_SEPARATOR; + yield [null, false, Config::DEFAULT_CACHE_PATH, FileCacheManager::class]; yield [null, true, null, null]; - $path = __DIR__.'/Fixtures/directoryWithCustomCacheManager/.twig-cs-fixer.php'; + $path = __DIR__.$slash.'Fixtures'.$slash.'directoryWithCustomCacheManager'.$slash.'.twig-cs-fixer.php'; yield [$path, false, Config::DEFAULT_CACHE_PATH, NullCacheManager::class]; yield [$path, true, null, null]; - $path = __DIR__.'/Fixtures/directoryWithCustomCacheFile/.twig-cs-fixer.php'; - $cachePath = __DIR__.'/Fixtures/directoryWithCustomCacheFile/.twig-cs-fixer.cache'; + $path = __DIR__.$slash.'Fixtures'.$slash.'directoryWithCustomCacheFile'.$slash.'.twig-cs-fixer.php'; + $cachePath = __DIR__.$slash.'Fixtures'.$slash.'directoryWithCustomCacheFile'.$slash.'.twig-cs-fixer.cache'; yield [$path, false, $cachePath, FileCacheManager::class]; yield [$path, true, null, null]; - $path = __DIR__.'/Fixtures/directoryWithNoCacheFile/.twig-cs-fixer.php'; + $path = __DIR__.$slash.'Fixtures'.$slash.'directoryWithNoCacheFile'.$slash.'.twig-cs-fixer.php'; yield [$path, false, null, null]; yield [$path, true, null, null]; } diff --git a/tests/FileTestCase.php b/tests/FileTestCase.php index b77c07d2..10179b51 100644 --- a/tests/FileTestCase.php +++ b/tests/FileTestCase.php @@ -22,7 +22,7 @@ protected function setUp(): void { parent::setUp(); - $fixtureDir = $this->getDir().'/Fixtures'; + $fixtureDir = $this->getDir().\DIRECTORY_SEPARATOR.'Fixtures'; $tmpFixtures = $this->getTmpPath($fixtureDir); if ($tmpFixtures !== $fixtureDir) { @@ -87,7 +87,7 @@ private function getTmp(): string if (false === $tmp) { $this->tmp = $this->getDir(); } else { - $this->tmp = $tmp.'/twig-cs-fixer'; + $this->tmp = $tmp.\DIRECTORY_SEPARATOR.'twig-cs-fixer'; } } diff --git a/tests/Report/Reporter/CheckstyleReporterTest.php b/tests/Report/Reporter/CheckstyleReporterTest.php index aa93dbef..47fe815d 100644 --- a/tests/Report/Reporter/CheckstyleReporterTest.php +++ b/tests/Report/Reporter/CheckstyleReporterTest.php @@ -21,9 +21,10 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) { $textFormatter = new CheckstyleReporter(); - $file = __DIR__.'/Fixtures/file.twig'; - $file2 = __DIR__.'/Fixtures/file2.twig'; - $file3 = __DIR__.'/Fixtures/file3.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'file.twig'; + $file2 = __DIR__.$slash.'Fixtures'.$slash.'file2.twig'; + $file3 = __DIR__.$slash.'Fixtures'.$slash.'file3.twig'; $report = new Report([new \SplFileInfo($file), new \SplFileInfo($file2), new \SplFileInfo($file3)]); $violation0 = new Violation( @@ -81,7 +82,7 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) $textFormatter->display($output, $report, $level, $debug); $text = $output->fetch(); - static::assertStringContainsString($expected, $text); + static::assertSame($expected, rtrim($text)); } /** @@ -89,26 +90,30 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) */ public static function displayDataProvider(): iterable { + $slash = \DIRECTORY_SEPARATOR; + yield [ sprintf( << - + - + - + EOD, - __DIR__ + __DIR__.$slash.'Fixtures'.$slash.'file.twig', + __DIR__.$slash.'Fixtures'.$slash.'file2.twig', + __DIR__.$slash.'Fixtures'.$slash.'file3.twig', ), null, false, @@ -119,16 +124,17 @@ public static function displayDataProvider(): iterable << - + - + EOD, - __DIR__ + __DIR__.$slash.'Fixtures'.$slash.'file.twig', + __DIR__.$slash.'Fixtures'.$slash.'file3.twig', ), Report::MESSAGE_TYPE_ERROR, false, @@ -139,16 +145,17 @@ public static function displayDataProvider(): iterable << - + - + EOD, - __DIR__ + __DIR__.$slash.'Fixtures'.$slash.'file.twig', + __DIR__.$slash.'Fixtures'.$slash.'file3.twig', ), Report::MESSAGE_TYPE_ERROR, true, diff --git a/tests/Report/Reporter/GithubReporterTest.php b/tests/Report/Reporter/GithubReporterTest.php index 1769034c..a8fe00a8 100644 --- a/tests/Report/Reporter/GithubReporterTest.php +++ b/tests/Report/Reporter/GithubReporterTest.php @@ -21,7 +21,8 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) { $textFormatter = new GithubReporter(); - $file = __DIR__.'/Fixtures/file.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'file.twig'; $report = new Report([new \SplFileInfo($file)]); $violation0 = new Violation( @@ -61,7 +62,7 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) $textFormatter->display($output, $report, $level, $debug); $text = $output->fetch(); - static::assertStringContainsString($expected, $text); + static::assertSame($expected, rtrim($text)); } /** @@ -69,15 +70,17 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) */ public static function displayDataProvider(): iterable { + $slash = \DIRECTORY_SEPARATOR; + yield [ sprintf( <<display($output, $report, $level, $debug); $text = $output->fetch(); - static::assertStringContainsString($expected, $text); + static::assertSame($expected, rtrim($text)); } /** @@ -89,34 +90,38 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) */ public static function displayDataProvider(): iterable { + $slash = \DIRECTORY_SEPARATOR; + yield [ sprintf( << - + - + - + - + - + - + EOD, - __DIR__ + __DIR__.$slash.'Fixtures'.$slash.'file.twig', + __DIR__.$slash.'Fixtures'.$slash.'file2.twig', + __DIR__.$slash.'Fixtures'.$slash.'file3.twig', ), null, false, @@ -127,28 +132,30 @@ public static function displayDataProvider(): iterable - + - + - + - + - + - + EOD, - __DIR__ + __DIR__.$slash.'Fixtures'.$slash.'file.twig', + __DIR__.$slash.'Fixtures'.$slash.'file2.twig', + __DIR__.$slash.'Fixtures'.$slash.'file3.twig', ), null, true, @@ -159,9 +166,10 @@ public function testDisplaySuccess(): void { $textFormatter = new JUnitReporter(); - $file = __DIR__.'/Fixtures/file.twig'; - $file2 = __DIR__.'/Fixtures/file2.twig'; - $file3 = __DIR__.'/Fixtures/file3.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'file.twig'; + $file2 = __DIR__.$slash.'Fixtures'.$slash.'file2.twig'; + $file3 = __DIR__.$slash.'Fixtures'.$slash.'file3.twig'; $report = new Report([new \SplFileInfo($file), new \SplFileInfo($file2), new \SplFileInfo($file3)]); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); @@ -178,6 +186,6 @@ public function testDisplaySuccess(): void EOD; $text = $output->fetch(); - static::assertStringContainsString($expected, $text); + static::assertSame($expected, rtrim($text)); } } diff --git a/tests/Report/Reporter/NullReporterTest.php b/tests/Report/Reporter/NullReporterTest.php index c1a1d6bc..dc820f9c 100644 --- a/tests/Report/Reporter/NullReporterTest.php +++ b/tests/Report/Reporter/NullReporterTest.php @@ -20,7 +20,8 @@ public function testDisplayErrors(?string $level): void { $textFormatter = new NullReporter(); - $file = __DIR__.'/Fixtures/file.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'file.twig'; $report = new Report([new \SplFileInfo($file)]); $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file); diff --git a/tests/Report/Reporter/TextReporterTest.php b/tests/Report/Reporter/TextReporterTest.php index 812de6dc..dfe4db57 100644 --- a/tests/Report/Reporter/TextReporterTest.php +++ b/tests/Report/Reporter/TextReporterTest.php @@ -21,7 +21,8 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) { $textFormatter = new TextReporter(); - $file = __DIR__.'/Fixtures/file.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'file.twig'; $report = new Report([new \SplFileInfo($file)]); $violation0 = new Violation( @@ -70,10 +71,12 @@ public function testDisplayErrors(string $expected, ?string $level, bool $debug) */ public static function displayDataProvider(): iterable { + $slash = \DIRECTORY_SEPARATOR; + yield [ sprintf( <<> | Notice\e[39m @@ -92,7 +95,7 @@ public static function displayDataProvider(): iterable \e[33mFATAL\e[39m \e[31m>> | Fatal\e[39m --------- --------------------------------------- EOD, - __DIR__ + __DIR__.$slash.'Fixtures'.$slash.'file.twig' ), null, false, @@ -101,7 +104,7 @@ public static function displayDataProvider(): iterable yield [ sprintf( <<> | Fatal\e[39m ------- ----------------------------------- EOD, - __DIR__ + __DIR__.$slash.'Fixtures'.$slash.'file.twig' ), Report::MESSAGE_TYPE_ERROR, false, @@ -120,7 +123,7 @@ public static function displayDataProvider(): iterable yield [ sprintf( <<> | FatalId\e[39m ------- ----------------------------------- EOD, - __DIR__ + __DIR__.$slash.'Fixtures'.$slash.'file.twig' ), Report::MESSAGE_TYPE_ERROR, true, @@ -141,14 +144,16 @@ public function testDisplaySuccess(): void { $textFormatter = new TextReporter(); - $file = __DIR__.'/Fixtures/file.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'file.twig'; + $report = new Report([new \SplFileInfo($file)]); $output = new BufferedOutput(); $textFormatter->display($output, $report, null, false); $text = $output->fetch(); - static::assertStringNotContainsString(sprintf('KO %s/Fixtures/file.twig', __DIR__), $text); + static::assertStringNotContainsString(sprintf('KO %s', $file), $text); static::assertStringContainsString('[OK]', $text); } @@ -156,8 +161,9 @@ public function testDisplayMultipleFiles(): void { $textFormatter = new TextReporter(); - $file = __DIR__.'/Fixtures/file.twig'; - $file2 = __DIR__.'/Fixtures/file2.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'file.twig'; + $file2 = __DIR__.$slash.'Fixtures'.$slash.'file2.twig'; $report = new Report([new \SplFileInfo($file), new \SplFileInfo($file2)]); $violation = new Violation(Violation::LEVEL_ERROR, 'Error', $file, null, new ViolationId(line: 3)); @@ -169,7 +175,7 @@ public function testDisplayMultipleFiles(): void static::assertStringContainsString( sprintf( <<fetch() ); @@ -189,7 +195,8 @@ public function testDisplayNotFoundFile(): void { $textFormatter = new TextReporter(); - $file = __DIR__.'/Fixtures/fileNotFound.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'fileNotFound.twig'; $report = new Report([new \SplFileInfo($file)]); $violation = new Violation(Violation::LEVEL_ERROR, 'Error', $file, null, new ViolationId(line: 1)); @@ -201,14 +208,14 @@ public function testDisplayNotFoundFile(): void static::assertStringContainsString( sprintf( <<> | Error ------- -------------- EOD, - __DIR__ + $file ), - $output->fetch() + rtrim($output->fetch()) ); } @@ -219,7 +226,9 @@ public function testDisplayBlock(string $expected, int $level): void { $textFormatter = new TextReporter(); - $file = __DIR__.'/Fixtures/file.twig'; + $slash = \DIRECTORY_SEPARATOR; + $file = __DIR__.$slash.'Fixtures'.$slash.'file.twig'; + $report = new Report([new \SplFileInfo($file)]); $violation = new Violation($level, 'Message', $file, null, new ViolationId(line: 1)); diff --git a/tests/Token/Tokenizer/TokenizerTest.php b/tests/Token/Tokenizer/TokenizerTest.php index 218796f9..04fdee06 100644 --- a/tests/Token/Tokenizer/TokenizerTest.php +++ b/tests/Token/Tokenizer/TokenizerTest.php @@ -30,7 +30,7 @@ public function testTokenize(): void [ [ new Token(Token::TEXT_TYPE, 1, 1, $filePath, '
test
'), - new Token(Token::EOL_TYPE, 1, 16, $filePath, "\n"), + new Token(Token::EOL_TYPE, 1, 16, $filePath, \PHP_EOL), new Token(Token::EOF_TYPE, 2, 1, $filePath), ], [], @@ -65,7 +65,7 @@ public function testTokenizeWithCustomOperators(): void new Token(Token::NAME_TYPE, 1, 22, $filePath, 'sumVariable'), new Token(Token::WHITESPACE_TYPE, 1, 33, $filePath, ' '), new Token(Token::VAR_END_TYPE, 1, 34, $filePath, '}}'), - new Token(Token::EOL_TYPE, 1, 36, $filePath, "\n"), + new Token(Token::EOL_TYPE, 1, 36, $filePath, \PHP_EOL), new Token(Token::EOF_TYPE, 2, 1, $filePath), ], $tokenizer->tokenize($source)[0]