Skip to content

Commit

Permalink
chore: add header's multi values matchers example
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Jan 19, 2024
1 parent ddf67b3 commit 2993bce
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 10 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@
"extra": {
"downloads": {
"pact-ffi-headers": {
"version": "0.4.11",
"version": "0.4.12",
"url": "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v{$version}/pact.h",
"path": "bin/pact-ffi-headers/pact.h"
},
"pact-ffi-lib": {
"version": "0.4.11",
"version": "0.4.12",
"variables": {
"{$prefix}": "PHP_OS_FAMILY === 'Windows' ? 'pact_ffi' : 'libpact_ffi'",
"{$os}": "PHP_OS === 'Darwin' ? 'osx' : strtolower(PHP_OS_FAMILY)",
Expand Down
16 changes: 16 additions & 0 deletions example/matchers/consumer/tests/Service/MatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ public function testGetMatchers(): void
$response
->setStatus($this->matcher->statusCode(HttpStatus::SERVER_ERROR, 512))
->addHeader('Content-Type', 'application/json')
->addHeader('X-IMPROVED', [
$this->matcher->values([
'like',
'regex',
'values',
'arrayContaining',
]),
])
->addHeader('X-REMOVED', [
$this->matcher->arrayContaining([
'ipv4AddressV3',
'ipv6AddressV3',
'emailV3',
'statusCode',
]),
])
->setBody([
'like' => $this->matcher->like(['key' => 'value']),
'likeNull' => $this->matcher->like(null),
Expand Down
94 changes: 87 additions & 7 deletions example/matchers/pacts/matchersConsumer-matchersProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@
]
},
"query": {
"$.pages": {
"locales[]": {
"combine": "AND",
"matchers": [
{
"match": "regex",
"regex": "\\d+"
"regex": "^[a-z]{2}-[A-Z]{2}$"
}
]
},
"$['locales[]']": {
"pages": {
"combine": "AND",
"matchers": [
{
"match": "regex",
"regex": "^[a-z]{2}-[A-Z]{2}$"
"regex": "\\d+"
}
]
}
Expand Down Expand Up @@ -159,6 +159,15 @@
"headers": {
"Content-Type": [
"application/json"
],
"X-IMPROVED": [
"like",
"regex",
"values",
"arrayContaining"
],
"X-REMOVED": [
""
]
},
"matchingRules": {
Expand Down Expand Up @@ -570,7 +579,78 @@
]
}
},
"header": {},
"header": {
"X-IMPROVED": {
"combine": "AND",
"matchers": [
{
"match": "values"
}
]
},
"X-REMOVED": {
"combine": "AND",
"matchers": [
{
"match": "arrayContains",
"variants": [
{
"index": 0,
"rules": {
"": {
"combine": "AND",
"matchers": [
{
"match": "equality"
}
]
}
}
},
{
"index": 0,
"rules": {
"": {
"combine": "AND",
"matchers": [
{
"match": "equality"
}
]
}
}
},
{
"index": 0,
"rules": {
"": {
"combine": "AND",
"matchers": [
{
"match": "equality"
}
]
}
}
},
{
"index": 0,
"rules": {
"": {
"combine": "AND",
"matchers": [
{
"match": "equality"
}
]
}
}
}
]
}
]
}
},
"status": {
"$": {
"combine": "AND",
Expand All @@ -591,9 +671,9 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.11",
"ffi": "0.4.12",
"mockserver": "1.2.4",
"models": "1.1.12"
"models": "1.1.14"
},
"pactSpecification": {
"version": "4.0"
Expand Down
14 changes: 13 additions & 1 deletion example/matchers/provider/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,19 @@

return $response
->withHeader('Content-Type', 'application/json')
->withStatus(503);
->withStatus(503)
->withHeader('X-IMPROVED', [
'regex',
'like',
'values',
'arrayContaining',
])
->withHeader('X-REMOVED', [
'ipv4AddressV3',
'ipv6AddressV3',
'emailV3',
'statusCode',
]);
});

$app->post('/pact-change-state', function (Request $request, Response $response) {
Expand Down

0 comments on commit 2993bce

Please sign in to comment.