mirror of
https://github.com/Neur0toxine/pock.git
synced 2024-11-28 15:56:09 +03:00
RecursiveLtrArrayComparator
improvement and test
This commit is contained in:
parent
b4142304ab
commit
2a124cfdd8
@ -47,7 +47,10 @@ class RecursiveLtrArrayComparator extends RecursiveArrayComparator
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($needle as $key => $value) {
|
foreach ($needle as $key => $value) {
|
||||||
if (is_array($value) && !self::recursiveCompareArrays($value, $haystack[$key])) {
|
if (
|
||||||
|
is_array($value) &&
|
||||||
|
(!is_array($haystack[$key]) || !self::recursiveCompareArrays($value, $haystack[$key]))
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
tests/src/Comparator/RecursiveArrayLtrComparatorTest.php
Normal file
42
tests/src/Comparator/RecursiveArrayLtrComparatorTest.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category RecursiveArrayLtrComparatorTest
|
||||||
|
* @package Pock\Tests\Comparator
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Pock\Tests\Comparator;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Pock\Comparator\ComparatorLocator;
|
||||||
|
use Pock\Comparator\RecursiveLtrArrayComparator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RecursiveArrayLtrComparatorTest
|
||||||
|
*
|
||||||
|
* @category RecursiveArrayLtrComparatorTest
|
||||||
|
* @package Pock\Tests\Comparator
|
||||||
|
*/
|
||||||
|
class RecursiveArrayLtrComparatorTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testMatches(): void
|
||||||
|
{
|
||||||
|
$needle = [
|
||||||
|
'filter' => [
|
||||||
|
'createdAtFrom' => '2020-01-01 00:00:00',
|
||||||
|
'createdAtTo' => '2021-08-01 00:00:00',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$haystack = [
|
||||||
|
'filter' => [
|
||||||
|
'createdAtFrom' => '2020-01-01 00:00:00',
|
||||||
|
'createdAtTo' => '2021-08-01 00:00:00',
|
||||||
|
],
|
||||||
|
'test' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
self::assertTrue(ComparatorLocator::get(RecursiveLtrArrayComparator::class)->compare($needle, $haystack));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user