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 11namespace SebastianBergmann\Comparator; 12 13use SebastianBergmann\Exporter\Exporter; 14 15/** 16 * Abstract base class for comparators which compare values for equality. 17 */ 18abstract 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 First value to compare 56 * @param mixed $actual Second value to compare 57 * @param float $delta Allowed numerical distance between two values to consider them equal 58 * @param bool $canonicalize Arrays are sorted before comparison when set to true 59 * @param bool $ignoreCase Case is ignored when set to true 60 * 61 * @throws ComparisonFailure 62 */ 63 abstract public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false); 64} 65