ComparisonFailureTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. final class ComparisonFailureTest extends TestCase
  16. {
  17. public function testComparisonFailure()
  18. {
  19. $actual = "\nB\n";
  20. $expected = "\nA\n";
  21. $message = 'Test message';
  22. $failure = new ComparisonFailure(
  23. $expected,
  24. $actual,
  25. '|' . $expected,
  26. '|' . $actual,
  27. false,
  28. $message
  29. );
  30. $this->assertSame($actual, $failure->getActual());
  31. $this->assertSame($expected, $failure->getExpected());
  32. $this->assertSame('|' . $actual, $failure->getActualAsString());
  33. $this->assertSame('|' . $expected, $failure->getExpectedAsString());
  34. $diff = '
  35. --- Expected
  36. +++ Actual
  37. @@ @@
  38. |
  39. -A
  40. +B
  41. ';
  42. $this->assertSame($diff, $failure->getDiff());
  43. $this->assertSame($message . $diff, $failure->toString());
  44. }
  45. public function testDiffNotPossible()
  46. {
  47. $failure = new ComparisonFailure('a', 'b', false, false, true, 'test');
  48. $this->assertSame('', $failure->getDiff());
  49. $this->assertSame('test', $failure->toString());
  50. }
  51. }