diff --git a/src/Comparator/RecursiveLtrArrayComparator.php b/src/Comparator/RecursiveLtrArrayComparator.php index 94c8876..de67a5e 100644 --- a/src/Comparator/RecursiveLtrArrayComparator.php +++ b/src/Comparator/RecursiveLtrArrayComparator.php @@ -47,7 +47,10 @@ class RecursiveLtrArrayComparator extends RecursiveArrayComparator } 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; } diff --git a/tests/src/Comparator/RecursiveArrayLtrComparatorTest.php b/tests/src/Comparator/RecursiveArrayLtrComparatorTest.php new file mode 100644 index 0000000..c72a5bc --- /dev/null +++ b/tests/src/Comparator/RecursiveArrayLtrComparatorTest.php @@ -0,0 +1,42 @@ + [ + '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)); + } +}