Skip to content

Commit

Permalink
Merge pull request #356 from tienvx/values-matcher-values-only
Browse files Browse the repository at this point in the history
fix: values matcher doesn't work if values is array with keys
  • Loading branch information
tienvx authored Oct 31, 2023
2 parents 3181d92 + 7bafeac commit 61a48bf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
10 changes: 10 additions & 0 deletions example/matchers/consumer/tests/Service/MatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public function testGetMatchers()
]),
'notEmpty' => $this->matcher->notEmpty(['1','2','3']),
'semver' => $this->matcher->semver('10.0.0-alpha4'),
'values' => $this->matcher->values([
'a' => 'a',
'b' => 'bb',
'c' => 'ccc',
]),
'contentType' => $this->matcher->contentType('text/html'),
]);

Expand Down Expand Up @@ -136,6 +141,11 @@ public function testGetMatchers()
],
'notEmpty' => ['1', '2', '3'],
'semver' => '10.0.0-alpha4',
'values' => [
'a',
'bb',
'ccc',
],
'contentType' => 'text/html',
], $matchersResult);
}
Expand Down
15 changes: 14 additions & 1 deletion example/matchers/pacts/matchersConsumer-matchersProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@
"time": "23:59::58",
"timeISO8601": "T22:44:30.652Z",
"timestampRFC3339": "Mon, 31 Oct 2016 15:21:41 -0400",
"uuid": "52c9585e-f345-4964-aa28-a45c64b2b2eb"
"uuid": "52c9585e-f345-4964-aa28-a45c64b2b2eb",
"values": [
"a",
"bb",
"ccc"
]
},
"contentType": "application/json",
"encoded": false
Expand Down Expand Up @@ -452,6 +457,14 @@
"regex": "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$"
}
]
},
"$.values": {
"combine": "AND",
"matchers": [
{
"match": "values"
}
]
}
},
"header": {}
Expand Down
5 changes: 5 additions & 0 deletions example/matchers/provider/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
],
'notEmpty' => [111],
'semver' => '0.27.1-beta2',
'values' => [
'a',
'bb',
'ccc',
],
'contentType' =>
<<<HTML
<!DOCTYPE html>
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPact/Consumer/Matcher/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public function statusCode(string $status): array
public function values(array $values): array
{
return [
'value' => $values,
'value' => array_values($values),
'pact:matcher:type' => 'values',
];
}
Expand Down
17 changes: 17 additions & 0 deletions tests/PhpPact/Consumer/Matcher/MatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,23 @@ public function testValues()
$this->assertEquals($expected, $actual);
}

public function testValuesWithKeys()
{
$expected = [
'pact:matcher:type' => 'values',
'value' => [
'item 1',
'item 2'
],
];
$actual = $this->matcher->values([
'key 1' => 'item 1',
'key 2' => 'item 2'
]);

$this->assertEquals($expected, $actual);
}

public function testContentType()
{
$expected = [
Expand Down

0 comments on commit 61a48bf

Please sign in to comment.