Upgrade framework
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of the Comparator package.
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function abs;
|
||||
use function is_float;
|
||||
use function is_infinite;
|
||||
use function is_nan;
|
||||
use function is_numeric;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Compares numerical values for equality.
|
||||
*/
|
||||
@@ -18,16 +25,15 @@ class NumericComparator extends ScalarComparator
|
||||
/**
|
||||
* Returns whether the comparator can compare two values.
|
||||
*
|
||||
* @param mixed $expected The first value to compare
|
||||
* @param mixed $actual The second value to compare
|
||||
* @param mixed $expected The first value to compare
|
||||
* @param mixed $actual The second value to compare
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function accepts($expected, $actual)
|
||||
{
|
||||
// all numerical values, but not if one of them is a double
|
||||
// or both of them are strings
|
||||
// all numerical values, but not if both of them are strings
|
||||
return is_numeric($expected) && is_numeric($actual) &&
|
||||
!(is_double($expected) || is_double($actual)) &&
|
||||
!(is_string($expected) && is_string($actual));
|
||||
}
|
||||
|
||||
@@ -42,14 +48,14 @@ class NumericComparator extends ScalarComparator
|
||||
*
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
|
||||
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)/*: void*/
|
||||
{
|
||||
if (is_infinite($actual) && is_infinite($expected)) {
|
||||
if ($this->isInfinite($actual) && $this->isInfinite($expected)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((is_infinite($actual) xor is_infinite($expected)) ||
|
||||
(is_nan($actual) or is_nan($expected)) ||
|
||||
if (($this->isInfinite($actual) xor $this->isInfinite($expected)) ||
|
||||
($this->isNan($actual) || $this->isNan($expected)) ||
|
||||
abs($actual - $expected) > $delta) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
@@ -65,4 +71,14 @@ class NumericComparator extends ScalarComparator
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function isInfinite($value): bool
|
||||
{
|
||||
return is_float($value) && is_infinite($value);
|
||||
}
|
||||
|
||||
private function isNan($value): bool
|
||||
{
|
||||
return is_float($value) && is_nan($value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user