ResourceComparator.php (2033B)
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 /** 14 * Compares resources for equality. 15 */ 16 class ResourceComparator extends Comparator 17 { 18 /** 19 * Returns whether the comparator can compare two values. 20 * 21 * @param mixed $expected The first value to compare 22 * @param mixed $actual The second value to compare 23 * @return bool 24 */ 25 public function accepts($expected, $actual) 26 { 27 return is_resource($expected) && is_resource($actual); 28 } 29 30 /** 31 * Asserts that two values are equal. 32 * 33 * @param mixed $expected The first value to compare 34 * @param mixed $actual The second value to compare 35 * @param float $delta The allowed numerical distance between two values to 36 * consider them equal 37 * @param bool $canonicalize If set to TRUE, arrays are sorted before 38 * comparison 39 * @param bool $ignoreCase If set to TRUE, upper- and lowercasing is 40 * ignored when comparing string values 41 * @throws ComparisonFailure Thrown when the comparison 42 * fails. Contains information about the 43 * specific errors that lead to the failure. 44 */ 45 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false) 46 { 47 if ($actual != $expected) { 48 throw new ComparisonFailure( 49 $expected, 50 $actual, 51 $this->exporter->export($expected), 52 $this->exporter->export($actual) 53 ); 54 } 55 } 56 }