ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Comparator.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
15 final class Comparator extends \SebastianBergmann\Comparator\Comparator
16 {
17  public function accepts($expected, $actual)
18  {
19  return $expected instanceof Enum && (
20  $actual instanceof Enum || $actual === null
21  );
22  }
23 
30  public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
31  {
32  if ($expected->equals($actual)) {
33  return;
34  }
35 
36  throw new ComparisonFailure(
37  $expected,
38  $actual,
39  $this->formatEnum($expected),
40  $this->formatEnum($actual),
41  false,
42  'Failed asserting that two Enums are equal.'
43  );
44  }
45 
46  private function formatEnum(Enum $enum = null)
47  {
48  if ($enum === null) {
49  return "null";
50  }
51 
52  return get_class($enum)."::{$enum->getKey()}()";
53  }
54 }
assertEquals($expected, $actual, $delta=0.0, $canonicalize=false, $ignoreCase=false)
Definition: Comparator.php:30
Base Enum class.
Definition: Enum.php:22
Use this Comparator to get nice output when using PHPUnit assertEquals() with Enums.
Definition: Comparator.php:15
accepts($expected, $actual)
Definition: Comparator.php:17