3 * This file is part of the Comparator package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace SebastianBergmann\Comparator;
13 use SebastianBergmann\Diff\Differ;
16 * Thrown when an assertion for string equality failed.
18 class ComparisonFailure extends \RuntimeException
21 * Expected value of the retrieval which does not match $actual.
27 * Actually retrieved value which does not match $expected.
33 * The string representation of the expected value
36 protected $expectedAsString;
39 * The string representation of the actual value
42 protected $actualAsString;
50 * Optional message which is placed in front of the first line
51 * returned by toString().
57 * Initialises with the expected value and the actual value.
59 * @param mixed $expected Expected value retrieved.
60 * @param mixed $actual Actual value retrieved.
61 * @param string $expectedAsString
62 * @param string $actualAsString
63 * @param bool $identical
64 * @param string $message A string which is prefixed on all returned lines
65 * in the difference output.
67 public function __construct($expected, $actual, $expectedAsString, $actualAsString, $identical = false, $message = '')
69 $this->expected = $expected;
70 $this->actual = $actual;
71 $this->expectedAsString = $expectedAsString;
72 $this->actualAsString = $actualAsString;
73 $this->message = $message;
79 public function getActual()
87 public function getExpected()
89 return $this->expected;
95 public function getActualAsString()
97 return $this->actualAsString;
103 public function getExpectedAsString()
105 return $this->expectedAsString;
111 public function getDiff()
113 if (!$this->actualAsString && !$this->expectedAsString) {
117 $differ = new Differ("\n--- Expected\n+++ Actual\n");
119 return $differ->diff($this->expectedAsString, $this->actualAsString);
125 public function toString()
127 return $this->message . $this->getDiff();