123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * 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\UnifiedDiffer;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Differ\UnifiedDiffer
- */
- final class UnifiedDifferTest extends AbstractDifferTestCase
- {
- public function testDiffReturnsDiff(): void
- {
- $differ = new UnifiedDiffer();
- $file = __FILE__;
- $diff = '--- '.$file.'
- +++ '.$file.'
- @@ -2,7 +2,7 @@
- '.'
- function baz($options)
- {
- - if (!array_key_exists("foo", $options)) {
- + if (!\array_key_exists("foo", $options)) {
- throw new \InvalidArgumentException();
- }
- '.'
- ';
- self::assertSame($diff, $differ->diff($this->oldCode(), $this->newCode(), new \SplFileInfo($file)));
- }
- public function testDiffAddsQuotes(): void
- {
- $differ = new UnifiedDiffer();
- self::assertSame(
- '--- "test test test.txt"
- +++ "test test test.txt"
- @@ -1 +1 @@
- -a
- +b
- ',
- $differ->diff("a\n", "b\n", $this->createSplFileInfoDouble('/foo/bar/test test test.txt'))
- );
- }
- public function testDiffWithoutFile(): void
- {
- $differ = new UnifiedDiffer();
- self::assertSame(
- '--- Original
- +++ New
- @@ -1 +1 @@
- -a
- \ No newline at end of file
- +b
- \ No newline at end of file
- ',
- $differ->diff('a', 'b')
- );
- }
- private function createSplFileInfoDouble(string $filename): \SplFileInfo
- {
- return new class($filename) extends \SplFileInfo {
- public function getRealPath(): string
- {
- return $this->getFilename();
- }
- };
- }
- }
|