Comparator.php (2128B)
1 <?php 2 /* 3 * This file is part of the Comparator package. 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 11 namespace SebastianBergmann\Comparator; 12 13 use SebastianBergmann\Exporter\Exporter; 14 15 /** 16 * Abstract base class for comparators which compare values for equality. 17 */ 18 abstract class Comparator 19 { 20 /** 21 * @var Factory 22 */ 23 protected $factory; 24 25 /** 26 * @var Exporter 27 */ 28 protected $exporter; 29 30 public function __construct() 31 { 32 $this->exporter = new Exporter; 33 } 34 35 /** 36 * @param Factory $factory 37 */ 38 public function setFactory(Factory $factory) 39 { 40 $this->factory = $factory; 41 } 42 43 /** 44 * Returns whether the comparator can compare two values. 45 * 46 * @param mixed $expected The first value to compare 47 * @param mixed $actual The second value to compare 48 * @return bool 49 */ 50 abstract public function accepts($expected, $actual); 51 52 /** 53 * Asserts that two values are equal. 54 * 55 * @param mixed $expected The first value to compare 56 * @param mixed $actual The second value to compare 57 * @param float $delta The allowed numerical distance between two values to 58 * consider them equal 59 * @param bool $canonicalize If set to TRUE, arrays are sorted before 60 * comparison 61 * @param bool $ignoreCase If set to TRUE, upper- and lowercasing is 62 * ignored when comparing string values 63 * @throws ComparisonFailure Thrown when the comparison 64 * fails. Contains information about the 65 * specific errors that lead to the failure. 66 */ 67 abstract public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false); 68 }