Skip to content

Commit

Permalink
Added missing error in Array Matcher (#336)
Browse files Browse the repository at this point in the history
* Added missing error in Array Matcher

* Style change

* Split invalid value from can't match in ArrayMatcher
  • Loading branch information
norberttech authored Mar 25, 2022
1 parent c224c73 commit 7627761
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Matcher/ArrayMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Matcher/JsonMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}

0 comments on commit 7627761

Please sign in to comment.