Upgrade framework
This commit is contained in:
@@ -1,25 +1,36 @@
|
||||
<?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 array_key_exists;
|
||||
use function is_array;
|
||||
use function sort;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Compares arrays for equality.
|
||||
*
|
||||
* Arrays are equal if they contain the same key-value pairs.
|
||||
* The order of the keys does not matter.
|
||||
* The types of key-value pairs do not matter.
|
||||
*/
|
||||
class ArrayComparator extends Comparator
|
||||
{
|
||||
/**
|
||||
* 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)
|
||||
@@ -28,7 +39,7 @@ class ArrayComparator extends Comparator
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two values are equal.
|
||||
* Asserts that two arrays are equal.
|
||||
*
|
||||
* @param mixed $expected First value to compare
|
||||
* @param mixed $actual Second value to compare
|
||||
@@ -39,22 +50,23 @@ class ArrayComparator extends Comparator
|
||||
*
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = array())
|
||||
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = [])/*: void*/
|
||||
{
|
||||
if ($canonicalize) {
|
||||
sort($expected);
|
||||
sort($actual);
|
||||
}
|
||||
|
||||
$remaining = $actual;
|
||||
$expString = $actString = "Array (\n";
|
||||
$equal = true;
|
||||
$remaining = $actual;
|
||||
$actualAsString = "Array (\n";
|
||||
$expectedAsString = "Array (\n";
|
||||
$equal = true;
|
||||
|
||||
foreach ($expected as $key => $value) {
|
||||
unset($remaining[$key]);
|
||||
|
||||
if (!array_key_exists($key, $actual)) {
|
||||
$expString .= sprintf(
|
||||
$expectedAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$this->exporter->export($key),
|
||||
$this->exporter->shortenedExport($value)
|
||||
@@ -69,31 +81,28 @@ class ArrayComparator extends Comparator
|
||||
$comparator = $this->factory->getComparatorFor($value, $actual[$key]);
|
||||
$comparator->assertEquals($value, $actual[$key], $delta, $canonicalize, $ignoreCase, $processed);
|
||||
|
||||
$expString .= sprintf(
|
||||
$expectedAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$this->exporter->export($key),
|
||||
$this->exporter->shortenedExport($value)
|
||||
);
|
||||
$actString .= sprintf(
|
||||
|
||||
$actualAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$this->exporter->export($key),
|
||||
$this->exporter->shortenedExport($actual[$key])
|
||||
);
|
||||
} catch (ComparisonFailure $e) {
|
||||
$expString .= sprintf(
|
||||
$expectedAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$this->exporter->export($key),
|
||||
$e->getExpectedAsString()
|
||||
? $this->indent($e->getExpectedAsString())
|
||||
: $this->exporter->shortenedExport($e->getExpected())
|
||||
$e->getExpectedAsString() ? $this->indent($e->getExpectedAsString()) : $this->exporter->shortenedExport($e->getExpected())
|
||||
);
|
||||
|
||||
$actString .= sprintf(
|
||||
$actualAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$this->exporter->export($key),
|
||||
$e->getActualAsString()
|
||||
? $this->indent($e->getActualAsString())
|
||||
: $this->exporter->shortenedExport($e->getActual())
|
||||
$e->getActualAsString() ? $this->indent($e->getActualAsString()) : $this->exporter->shortenedExport($e->getActual())
|
||||
);
|
||||
|
||||
$equal = false;
|
||||
@@ -101,7 +110,7 @@ class ArrayComparator extends Comparator
|
||||
}
|
||||
|
||||
foreach ($remaining as $key => $value) {
|
||||
$actString .= sprintf(
|
||||
$actualAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$this->exporter->export($key),
|
||||
$this->exporter->shortenedExport($value)
|
||||
@@ -110,15 +119,15 @@ class ArrayComparator extends Comparator
|
||||
$equal = false;
|
||||
}
|
||||
|
||||
$expString .= ')';
|
||||
$actString .= ')';
|
||||
$expectedAsString .= ')';
|
||||
$actualAsString .= ')';
|
||||
|
||||
if (!$equal) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$expString,
|
||||
$actString,
|
||||
$expectedAsString,
|
||||
$actualAsString,
|
||||
false,
|
||||
'Failed asserting that two arrays are equal.'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user