Geen omschrijving

ComparisonFailureTest.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of sebastian/comparator.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Comparator;
  11. use PHPUnit\Framework\TestCase;
  12. /**
  13. * @covers \SebastianBergmann\Comparator\ComparisonFailure
  14. *
  15. * @uses \SebastianBergmann\Comparator\Factory
  16. */
  17. final class ComparisonFailureTest extends TestCase
  18. {
  19. public function testComparisonFailure(): void
  20. {
  21. $actual = "\nB\n";
  22. $expected = "\nA\n";
  23. $message = 'Test message';
  24. $failure = new ComparisonFailure(
  25. $expected,
  26. $actual,
  27. '|' . $expected,
  28. '|' . $actual,
  29. false,
  30. $message
  31. );
  32. $this->assertSame($actual, $failure->getActual());
  33. $this->assertSame($expected, $failure->getExpected());
  34. $this->assertSame('|' . $actual, $failure->getActualAsString());
  35. $this->assertSame('|' . $expected, $failure->getExpectedAsString());
  36. $diff = '
  37. --- Expected
  38. +++ Actual
  39. @@ @@
  40. |
  41. -A
  42. +B
  43. ';
  44. $this->assertSame($diff, $failure->getDiff());
  45. $this->assertSame($message . $diff, $failure->toString());
  46. }
  47. public function testDiffNotPossible(): void
  48. {
  49. $failure = new ComparisonFailure('a', 'b', false, false, true, 'test');
  50. $this->assertSame('', $failure->getDiff());
  51. $this->assertSame('test', $failure->toString());
  52. }
  53. }