diff --git a/example/matchers/consumer/tests/Service/MatchersTest.php b/example/matchers/consumer/tests/Service/MatchersTest.php index 275cc2ca..447d6b5a 100644 --- a/example/matchers/consumer/tests/Service/MatchersTest.php +++ b/example/matchers/consumer/tests/Service/MatchersTest.php @@ -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), @@ -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], diff --git a/example/matchers/pacts/matchersConsumer-matchersProvider.json b/example/matchers/pacts/matchersConsumer-matchersProvider.json index e5ad5469..aca3ab7b 100644 --- a/example/matchers/pacts/matchersConsumer-matchersProvider.json +++ b/example/matchers/pacts/matchersConsumer-matchersProvider.json @@ -84,6 +84,7 @@ "likeBool": true, "likeDecimal": 13.01, "likeInt": 13, + "likeNull": null, "likeString": "some string", "notEmpty": [ "1", @@ -359,6 +360,14 @@ } ] }, + "$.likeNull": { + "combine": "AND", + "matchers": [ + { + "match": "type" + } + ] + }, "$.likeString": { "combine": "AND", "matchers": [ diff --git a/example/matchers/provider/public/index.php b/example/matchers/provider/public/index.php index bf6961e6..b991881e 100644 --- a/example/matchers/provider/public/index.php +++ b/example/matchers/provider/public/index.php @@ -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], diff --git a/src/PhpPact/Consumer/Matcher/Matcher.php b/src/PhpPact/Consumer/Matcher/Matcher.php index 81f04f5b..e81859fd 100644 --- a/src/PhpPact/Consumer/Matcher/Matcher.php +++ b/src/PhpPact/Consumer/Matcher/Matcher.php @@ -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', diff --git a/tests/PhpPact/Consumer/Matcher/MatcherTest.php b/tests/PhpPact/Consumer/Matcher/MatcherTest.php index f5ab12eb..97af28cb 100644 --- a/tests/PhpPact/Consumer/Matcher/MatcherTest.php +++ b/tests/PhpPact/Consumer/Matcher/MatcherTest.php @@ -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); } /**