| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
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 |
|
|
|
12 |
use SebastianBergmann\Exporter\Exporter;
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* Abstract base class for comparators which compare values for equality.
|
|
|
16 |
*/
|
|
|
17 |
abstract class Comparator
|
|
|
18 |
{
|
|
|
19 |
/**
|
|
|
20 |
* @var Factory
|
|
|
21 |
*/
|
|
|
22 |
protected $factory;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* @var Exporter
|
|
|
26 |
*/
|
|
|
27 |
protected $exporter;
|
|
|
28 |
|
|
|
29 |
public function __construct()
|
|
|
30 |
{
|
|
|
31 |
$this->exporter = new Exporter;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public function setFactory(Factory $factory)/*: void*/
|
|
|
35 |
{
|
|
|
36 |
$this->factory = $factory;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Returns whether the comparator can compare two values.
|
|
|
41 |
*
|
|
|
42 |
* @param mixed $expected The first value to compare
|
|
|
43 |
* @param mixed $actual The second value to compare
|
|
|
44 |
*
|
|
|
45 |
* @return bool
|
|
|
46 |
*/
|
|
|
47 |
abstract public function accepts($expected, $actual);
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Asserts that two values are equal.
|
|
|
51 |
*
|
|
|
52 |
* @param mixed $expected First value to compare
|
|
|
53 |
* @param mixed $actual Second value to compare
|
|
|
54 |
* @param float $delta Allowed numerical distance between two values to consider them equal
|
|
|
55 |
* @param bool $canonicalize Arrays are sorted before comparison when set to true
|
|
|
56 |
* @param bool $ignoreCase Case is ignored when set to true
|
|
|
57 |
*
|
|
|
58 |
* @throws ComparisonFailure
|
|
|
59 |
*/
|
|
|
60 |
abstract public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false);
|
|
|
61 |
}
|