diff --git a/example/matchers/consumer/tests/Service/MatchersTest.php b/example/matchers/consumer/tests/Service/MatchersTest.php index 447d6b5a..4174640f 100644 --- a/example/matchers/consumer/tests/Service/MatchersTest.php +++ b/example/matchers/consumer/tests/Service/MatchersTest.php @@ -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'), ]); @@ -136,6 +141,11 @@ public function testGetMatchers() ], 'notEmpty' => ['1', '2', '3'], 'semver' => '10.0.0-alpha4', + 'values' => [ + 'a', + 'bb', + 'ccc', + ], 'contentType' => 'text/html', ], $matchersResult); } diff --git a/example/matchers/pacts/matchersConsumer-matchersProvider.json b/example/matchers/pacts/matchersConsumer-matchersProvider.json index aca3ab7b..cc42882d 100644 --- a/example/matchers/pacts/matchersConsumer-matchersProvider.json +++ b/example/matchers/pacts/matchersConsumer-matchersProvider.json @@ -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 @@ -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": {} diff --git a/example/matchers/provider/public/index.php b/example/matchers/provider/public/index.php index b991881e..e4d43c5a 100644 --- a/example/matchers/provider/public/index.php +++ b/example/matchers/provider/public/index.php @@ -48,6 +48,11 @@ ], 'notEmpty' => [111], 'semver' => '0.27.1-beta2', + 'values' => [ + 'a', + 'bb', + 'ccc', + ], 'contentType' => << diff --git a/src/PhpPact/Consumer/Matcher/Matcher.php b/src/PhpPact/Consumer/Matcher/Matcher.php index e81859fd..6fef4d1e 100644 --- a/src/PhpPact/Consumer/Matcher/Matcher.php +++ b/src/PhpPact/Consumer/Matcher/Matcher.php @@ -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', ]; } diff --git a/tests/PhpPact/Consumer/Matcher/MatcherTest.php b/tests/PhpPact/Consumer/Matcher/MatcherTest.php index 97af28cb..45393493 100644 --- a/tests/PhpPact/Consumer/Matcher/MatcherTest.php +++ b/tests/PhpPact/Consumer/Matcher/MatcherTest.php @@ -843,6 +843,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 = [