Skip to content

Commit

Permalink
chore: Add status code matcher example
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Oct 28, 2023
1 parent 67e9f20 commit 1448718
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions example/matchers/consumer/tests/Service/MatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use MatchersConsumer\Service\HttpClientService;
use PhpPact\Consumer\InteractionBuilder;
use PhpPact\Consumer\Matcher\HttpStatus;
use PhpPact\Consumer\Matcher\Matcher;
use PhpPact\Consumer\Model\ConsumerRequest;
use PhpPact\Consumer\Model\ProviderResponse;
Expand Down Expand Up @@ -74,6 +75,7 @@ public function testGetMatchers()
'notEmpty' => $this->matcher->notEmpty(['1','2','3']),
'semver' => $this->matcher->semver('10.0.0-alpha4'),
'contentType' => $this->matcher->contentType('text/html'),
'statusCode' => $this->matcher->statusCode(HttpStatus::SERVER_ERROR),
]);

$config = new MockServerConfig();
Expand Down Expand Up @@ -137,6 +139,7 @@ public function testGetMatchers()
'notEmpty' => ['1', '2', '3'],
'semver' => '10.0.0-alpha4',
'contentType' => 'text/html',
'statusCode' => null,
], $matchersResult);
}
}
10 changes: 10 additions & 0 deletions example/matchers/pacts/matchersConsumer-matchersProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"number": 123,
"regex": "500 miles",
"semver": "10.0.0-alpha4",
"statusCode": null,
"time": "23:59::58",
"timeISO8601": "T22:44:30.652Z",
"timestampRFC3339": "Mon, 31 Oct 2016 15:21:41 -0400",
Expand Down Expand Up @@ -417,6 +418,15 @@
}
]
},
"$.statusCode": {
"combine": "AND",
"matchers": [
{
"match": "statusCode",
"status": "serverError"
}
]
},
"$.time": {
"combine": "AND",
"matchers": [
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,
'statusCode' => 503,
]));

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

0 comments on commit 1448718

Please sign in to comment.