Skip to content

Empty array after mismatch fix #14

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

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/Coduo/PHPMatcher/Matcher/ArrayMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function iterateMatch(array $value, array $pattern)
}
}

if (!is_array($element)) {
if (!is_array($element) || empty($element)) {
$this->error = $this->propertyMatcher->getError();
return false;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Coduo/PHPMatcher/Matcher/ArrayMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public static function negativeMatchData()

return array(
array($simpleArr, $simpleDiff),
array(array("status" => "ok", "data" => array(array('foo'))), array("status" => "ok", "data" => array())),
array(array(1), array()),
array(array('key' => 'val'), array('key' => 'val2')),
array(array(1), array(2)),
Expand Down
9 changes: 9 additions & 0 deletions tests/Coduo/PHPMatcher/Matcher/JsonMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static function positiveMatches()

public static function negativeMatches()
{

return array(
array(
'{"users":["Norbert","Michał"]}',
Expand All @@ -129,6 +130,14 @@ public static function negativeMatches()
'{this_is_not_valid_json',
'{"users":["Michał","@string@"]}'
),
array(
'{"status":"ok","data":[]}',
'{"status":"ok","data":[{"id": 4,"code":"123987","name":"Anvill","short_description":"ACME Anvill","url":"http://test-store.example.com/p/123987","image":{"url":"http://test-store.example.com/i/123987-0.jpg","description":"ACME Anvill"},"price":95,"promotion_description":"Anvills sale"},{"id": 5,"code":"123988","name":"Red Anvill","short_description":"Red ACME Anvill","url":"http://test-store.example.com/p/123988","image":{"url":"http://test-store.example.com/i/123988-0.jpg","description":"ACME Anvill"},"price":44.99,"promotion_description":"Red is cheap"}]}'
),
array(
'{"foo":"foo val","bar":"bar val"}',
'{"foo":"foo val"}'
),
array(
array(),
'[]'
Expand Down