UnifiedDifferTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * @internal
  16. *
  17. * @covers \PhpCsFixer\Differ\UnifiedDiffer
  18. */
  19. final class UnifiedDifferTest extends AbstractDifferTestCase
  20. {
  21. public function testDiffReturnsDiff(): void
  22. {
  23. $differ = new UnifiedDiffer();
  24. $file = __FILE__;
  25. $diff = '--- '.$file.'
  26. +++ '.$file.'
  27. @@ -2,7 +2,7 @@
  28. '.'
  29. function baz($options)
  30. {
  31. - if (!array_key_exists("foo", $options)) {
  32. + if (!\array_key_exists("foo", $options)) {
  33. throw new \InvalidArgumentException();
  34. }
  35. '.'
  36. ';
  37. self::assertSame($diff, $differ->diff($this->oldCode(), $this->newCode(), new \SplFileInfo($file)));
  38. }
  39. public function testDiffAddsQuotes(): void
  40. {
  41. $differ = new UnifiedDiffer();
  42. self::assertSame(
  43. '--- "test test test.txt"
  44. +++ "test test test.txt"
  45. @@ -1 +1 @@
  46. -a
  47. +b
  48. ',
  49. $differ->diff("a\n", "b\n", new DummyTestSplFileInfo('/foo/bar/test test test.txt'))
  50. );
  51. }
  52. public function testDiffWithoutFile(): void
  53. {
  54. $differ = new UnifiedDiffer();
  55. self::assertSame(
  56. '--- Original
  57. +++ New
  58. @@ -1 +1 @@
  59. -a
  60. \ No newline at end of file
  61. +b
  62. \ No newline at end of file
  63. ',
  64. $differ->diff('a', 'b')
  65. );
  66. }
  67. }