-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScalarStrictComparator.php
59 lines (50 loc) · 1.54 KB
/
ScalarStrictComparator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php declare(strict_types = 1);
namespace LastDragon_ru\LaraASP\Testing\Comparators;
use Override;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Comparator\ScalarComparator;
use SebastianBergmann\Exporter\Exporter;
use function is_string;
use function mb_strtolower;
/**
* Makes comparison of scalars strict.
*/
class ScalarStrictComparator extends ScalarComparator {
/**
* @param array<array-key, mixed> $processed
*/
#[Override]
public function assertEquals(
mixed $expected,
mixed $actual,
float $delta = 0.0,
bool $canonicalize = false,
bool $ignoreCase = false,
array &$processed = [],
): void {
// Ignore case?
$actualNormalized = $actual;
$expectedNormalized = $expected;
if ($ignoreCase) {
if (is_string($actual)) {
$actualNormalized = mb_strtolower($actual);
}
if (is_string($expected)) {
$expectedNormalized = mb_strtolower($expected);
}
}
// Same?
if ($expectedNormalized === $actualNormalized) {
return;
}
// Nope
$exporter = new Exporter();
throw new ComparisonFailure(
expected : $expected,
actual : $actual,
expectedAsString: $exporter->export($expected),
actualAsString : $exporter->export($actual),
message : 'Failed asserting that two values are equal.',
);
}
}