* Dariusz Rumiński * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Tests\Differ; use PhpCsFixer\Differ\DiffConsoleFormatter; use PhpCsFixer\Tests\TestCase; use Symfony\Component\Console\Formatter\OutputFormatter; /** * @internal * * @covers \PhpCsFixer\Differ\DiffConsoleFormatter */ final class DiffConsoleFormatterTest extends TestCase { /** * @dataProvider provideDiffConsoleFormatterCases */ public function testDiffConsoleFormatter(string $expected, bool $isDecoratedOutput, string $template, string $diff, string $lineTemplate): void { $diffFormatter = new DiffConsoleFormatter($isDecoratedOutput, $template); self::assertSame( str_replace(PHP_EOL, "\n", $expected), str_replace(PHP_EOL, "\n", $diffFormatter->format($diff, $lineTemplate)) ); } /** * @return iterable */ public static function provideDiffConsoleFormatterCases(): iterable { yield [ \sprintf( ' ---------- begin diff ---------- '.' %s no change %s %s %s '.' ----------- end diff -----------', OutputFormatter::escape('@@ -12,51 +12,151 @@'), OutputFormatter::escape('-/**\\'), OutputFormatter::escape('+/*\\'), OutputFormatter::escape('+A') ), true, \sprintf( ' ---------- begin diff ----------%s%%s%s ----------- end diff -----------', PHP_EOL, PHP_EOL ), ' @@ -12,51 +12,151 @@ no change -/**\ +/*\ +A ', ' %s', ]; yield [ '[start] | '.' | @@ -12,51 +12,151 @@ | no change | '.' | -/**\ | +/*\ | +A | '.' [end]', false, \sprintf('[start]%s%%s%s[end]', PHP_EOL, PHP_EOL), ' @@ -12,51 +12,151 @@ no change '.' -/**\ +/*\ +A ', '| %s', ]; yield [ mb_convert_encoding("--- Original\n+ausgefüllt", 'ISO-8859-1'), true, '%s', mb_convert_encoding("--- Original\n+ausgefüllt", 'ISO-8859-1'), '%s', ]; yield [ mb_convert_encoding("--- Original\n+++ New\n@@ @@\n-ausgefüllt", 'ISO-8859-1'), true, '%s', mb_convert_encoding("--- Original\n+++ New\n@@ @@\n-ausgefüllt", 'ISO-8859-1'), '%s', ]; yield [ mb_convert_encoding("--- Original\n+++ New\n@@ @@\n-ausgefüllt", 'ISO-8859-1'), false, '%s', mb_convert_encoding("--- Original\n+++ New\n@@ @@\n-ausgefüllt", 'ISO-8859-1'), '%s', ]; } }