Skip to content

Added missing error in Array Matcher #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
);
}
}