UnifiedDifferTest.php 1.3 KB

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