ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MyCLabs\Enum\PHPUnit\Comparator Class Reference

Use this Comparator to get nice output when using PHPUnit assertEquals() with Enums. More...

+ Inheritance diagram for MyCLabs\Enum\PHPUnit\Comparator:
+ Collaboration diagram for MyCLabs\Enum\PHPUnit\Comparator:

Public Member Functions

 accepts ($expected, $actual)
 
 assertEquals ($expected, $actual, $delta=0.0, $canonicalize=false, $ignoreCase=false)
 

Private Member Functions

 formatEnum (Enum $enum=null)
 

Detailed Description

Use this Comparator to get nice output when using PHPUnit assertEquals() with Enums.

Add this to your PHPUnit bootstrap PHP file:

::getInstance()->register(new ());

Definition at line 15 of file Comparator.php.

Member Function Documentation

◆ accepts()

MyCLabs\Enum\PHPUnit\Comparator::accepts (   $expected,
  $actual 
)

Definition at line 17 of file Comparator.php.

18  {
19  return $expected instanceof Enum && (
20  $actual instanceof Enum || $actual === null
21  );
22  }

◆ assertEquals()

MyCLabs\Enum\PHPUnit\Comparator::assertEquals (   $expected,
  $actual,
  $delta = 0.0,
  $canonicalize = false,
  $ignoreCase = false 
)
Parameters
Enum$expected
Enum | null$actual
Returns
void

Definition at line 30 of file Comparator.php.

References MyCLabs\Enum\PHPUnit\Comparator\formatEnum().

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  }
+ Here is the call graph for this function:

◆ formatEnum()

MyCLabs\Enum\PHPUnit\Comparator::formatEnum ( Enum  $enum = null)
private

Definition at line 46 of file Comparator.php.

Referenced by MyCLabs\Enum\PHPUnit\Comparator\assertEquals().

47  {
48  if ($enum === null) {
49  return "null";
50  }
51 
52  return get_class($enum)."::{$enum->getKey()}()";
53  }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: