Skip to content

Commit

Permalink
chore: Showcase different behaviors of PHP when receiving multiple va…
Browse files Browse the repository at this point in the history
…lues of query parameter
  • Loading branch information
tienvx committed Oct 30, 2023
1 parent 1f8ae4a commit 9f13937
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getMatchers(): array
{
$response = $this->httpClient->get("{$this->baseUri}/matchers", [
'headers' => ['Accept' => 'application/json'],
'query' => 'ignore=statusCode&pages=2&pages=3',
'query' => 'ignore=statusCode&pages=2&pages=3&locales[]=fr-BE&locales[]=ru-RU',
]);

return \json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
Expand Down
17 changes: 15 additions & 2 deletions example/matchers/consumer/tests/Service/MatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ public function testGetMatchers()
->setPath($this->matcher->regex('/matchers', '^\/matchers$'))
->setQuery([
'ignore' => 'statusCode',
'pages' => [
json_encode($this->matcher->regex([1], '\d+')),
'pages' => [ // Consumer send multiple values, but provider receive single (last) value
json_encode($this->matcher->regex([1, 22], '\d+')),
],
'locales[]' => [ // Consumer send multiple values, provider receive all values
json_encode($this->matcher->regex(['en-US', 'en-AU'], '^[a-z]{2}-[A-Z]{2}$')),
],
])
->addHeader('Accept', 'application/json');
Expand Down Expand Up @@ -77,6 +80,11 @@ public function testGetMatchers()
'notEmpty' => $this->matcher->notEmpty(['1','2','3']),
'semver' => $this->matcher->semver('10.0.0-alpha4'),
'contentType' => $this->matcher->contentType('text/html'),
'query' => [
'ignore' => 'statusCode',
'pages' => '22',
'locales' => ['en-US', 'en-AU'],
],
]);

$config = new MockServerConfig();
Expand Down Expand Up @@ -140,6 +148,11 @@ public function testGetMatchers()
'notEmpty' => ['1', '2', '3'],
'semver' => '10.0.0-alpha4',
'contentType' => 'text/html',
'query' => [
'ignore' => 'statusCode',
'pages' => '22',
'locales' => ['en-US', 'en-AU'],
],
], $matchersResult);
}
}
24 changes: 23 additions & 1 deletion example/matchers/pacts/matchersConsumer-matchersProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
"regex": "\\d+"
}
]
},
"$['locales[]']": {
"combine": "AND",
"matchers": [
{
"match": "regex",
"regex": "^[a-z]{2}-[A-Z]{2}$"
}
]
}
}
},
Expand All @@ -46,8 +55,13 @@
"ignore": [
"statusCode"
],
"locales[]": [
"en-US",
"en-AU"
],
"pages": [
"1"
"1",
"22"
]
}
},
Expand Down Expand Up @@ -106,6 +120,14 @@
],
"nullValue": null,
"number": 123,
"query": {
"ignore": "statusCode",
"locales": [
"en-US",
"en-AU"
],
"pages": "22"
},
"regex": "500 miles",
"semver": "10.0.0-alpha4",
"time": "23:59::58",
Expand Down
1 change: 1 addition & 0 deletions example/matchers/provider/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
</body>
</html>
HTML,
'query' => $request->getQueryParams(),
]));

return $response->withHeader('Content-Type', 'application/json');
Expand Down

0 comments on commit 9f13937

Please sign in to comment.