UnifiedDifferTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Differ;
  13. use PhpCsFixer\Differ\UnifiedDiffer;
  14. /**
  15. * @author SpacePossum
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Differ\UnifiedDiffer
  20. */
  21. final class UnifiedDifferTest extends AbstractDifferTestCase
  22. {
  23. public function testDiffReturnsDiff(): void
  24. {
  25. $differ = new UnifiedDiffer();
  26. $file = __FILE__;
  27. $diff = '--- '.$file.'
  28. +++ '.$file.'
  29. @@ -2,7 +2,7 @@
  30. '.'
  31. function baz($options)
  32. {
  33. - if (!array_key_exists("foo", $options)) {
  34. + if (!\array_key_exists("foo", $options)) {
  35. throw new \InvalidArgumentException();
  36. }
  37. '.'
  38. ';
  39. static::assertSame($diff, $differ->diff($this->oldCode(), $this->newCode(), new \SplFileInfo($file)));
  40. }
  41. public function testDiffAddsQuotes(): void
  42. {
  43. $differ = new UnifiedDiffer();
  44. static::assertSame(
  45. '--- "test test test.txt"
  46. +++ "test test test.txt"
  47. @@ -1 +1 @@
  48. -a
  49. +b
  50. ',
  51. $differ->diff("a\n", "b\n", new DummyTestSplFileInfo('/foo/bar/test test test.txt'))
  52. );
  53. }
  54. }