Skip to content

Commit

Permalink
Merge pull request #350 from tienvx/allow-like-null
Browse files Browse the repository at this point in the history
Allow like null
  • Loading branch information
tienvx authored Oct 27, 2023
2 parents d2c42e8 + 06b4d67 commit 67e9f20
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions example/matchers/consumer/tests/Service/MatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function testGetMatchers()
->addHeader('Content-Type', 'application/json')
->setBody([
'like' => $this->matcher->like(['key' => 'value']),
'likeNull' => $this->matcher->like(null),
'eachLike' => $this->matcher->eachLike('item'),
'atLeastLike' => $this->matcher->atLeastLike(1, 5),
'atMostLike' => $this->matcher->atMostLike(1, 3),
Expand Down Expand Up @@ -98,6 +99,7 @@ public function testGetMatchers()
$this->assertTrue($verifyResult);
$this->assertEquals([
'like' => ['key' => 'value'],
'likeNull' => null,
'eachLike' => ['item'],
'atLeastLike' => [1, 1, 1, 1, 1],
'atMostLike' => [1],
Expand Down
9 changes: 9 additions & 0 deletions example/matchers/pacts/matchersConsumer-matchersProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"likeBool": true,
"likeDecimal": 13.01,
"likeInt": 13,
"likeNull": null,
"likeString": "some string",
"notEmpty": [
"1",
Expand Down Expand Up @@ -359,6 +360,14 @@
}
]
},
"$.likeNull": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.likeString": {
"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 @@ -12,6 +12,7 @@
$app->get('/matchers', function (Request $request, Response $response) {
$response->getBody()->write(\json_encode([
'like' => ['key' => 'another value'],
'likeNull' => null,
'eachLike' => ['item 1', 'item 2'],
'atLeastLike' => [1, 2, 3, 4, 5, 6],
'atMostLike' => [1, 2],
Expand Down
4 changes: 0 additions & 4 deletions src/PhpPact/Consumer/Matcher/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public function somethingLike(mixed $value): array
*/
public function like(mixed $value): array
{
if ($value === null) {
throw new Exception('Value must not be null.');
}

return [
'value' => $value,
'pact:matcher:type' => 'type',
Expand Down
7 changes: 4 additions & 3 deletions tests/PhpPact/Consumer/Matcher/MatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ protected function setUp(): void
/**
* @throws Exception
*/
public function testLikeNoValue()
public function testLikeNull(): void
{
$this->expectException(Exception::class);
$this->matcher->like(null);
$json = \json_encode($this->matcher->like(null));

$this->assertEquals('{"value":null,"pact:matcher:type":"type"}', $json);
}

/**
Expand Down

0 comments on commit 67e9f20

Please sign in to comment.