diff --git a/src/Matcher/ArrayMatcher.php b/src/Matcher/ArrayMatcher.php index f33e61a..9538fb3 100644 --- a/src/Matcher/ArrayMatcher.php +++ b/src/Matcher/ArrayMatcher.php @@ -153,7 +153,13 @@ private function iterateMatch(array $values, array $patterns, string $parentPath continue; } - if (!\is_array($value) || !$this->canMatch($pattern)) { + if (!\is_array($value)) { + return false; + } + + if (!$this->canMatch($pattern)) { + $this->addValuePatternDifference($value, $parentPath, $this->formatFullPath($parentPath, $path)); + return false; } diff --git a/tests/Matcher/JsonMatcherTest.php b/tests/Matcher/JsonMatcherTest.php index b9f015f..7101c27 100644 --- a/tests/Matcher/JsonMatcherTest.php +++ b/tests/Matcher/JsonMatcherTest.php @@ -321,4 +321,16 @@ public function test_error_when_json_value_is_invalid() : void $this->assertEquals('Invalid given JSON of value. Syntax error, malformed JSON', $this->matcher->getError()); } + + public function test_comparing_value_against_pattern_without_any_patterns() : void + { + $value = '{"availableLocales": ["en"]}'; + $pattern = '{"availableLocales": null}'; + + $this->assertFalse($this->matcher->match($value, $pattern)); + $this->assertEquals( + 'Value "Array(1)" does not match pattern "" at path: "[availableLocales]"', + $this->matcher->getError() + ); + } }