Skip to content

Commit 7627761

Browse files
authored
Added missing error in Array Matcher (#336)
* Added missing error in Array Matcher * Style change * Split invalid value from can't match in ArrayMatcher
1 parent c224c73 commit 7627761

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Matcher/ArrayMatcher.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,13 @@ private function iterateMatch(array $values, array $patterns, string $parentPath
153153
continue;
154154
}
155155

156-
if (!\is_array($value) || !$this->canMatch($pattern)) {
156+
if (!\is_array($value)) {
157+
return false;
158+
}
159+
160+
if (!$this->canMatch($pattern)) {
161+
$this->addValuePatternDifference($value, $parentPath, $this->formatFullPath($parentPath, $path));
162+
157163
return false;
158164
}
159165

tests/Matcher/JsonMatcherTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,16 @@ public function test_error_when_json_value_is_invalid() : void
321321

322322
$this->assertEquals('Invalid given JSON of value. Syntax error, malformed JSON', $this->matcher->getError());
323323
}
324+
325+
public function test_comparing_value_against_pattern_without_any_patterns() : void
326+
{
327+
$value = '{"availableLocales": ["en"]}';
328+
$pattern = '{"availableLocales": null}';
329+
330+
$this->assertFalse($this->matcher->match($value, $pattern));
331+
$this->assertEquals(
332+
'Value "Array(1)" does not match pattern "" at path: "[availableLocales]"',
333+
$this->matcher->getError()
334+
);
335+
}
324336
}

0 commit comments

Comments
 (0)