Skip to content

Commit

Permalink
Merge pull request #409 from tienvx/add-null-value-matcher-class
Browse files Browse the repository at this point in the history
refactor: Add NullValue matcher class
  • Loading branch information
tienvx committed Dec 17, 2023
2 parents a723622 + 90b2bfb commit 6b895c0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/PhpPact/Consumer/Matcher/Matchers/NullValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace PhpPact\Consumer\Matcher\Matchers;

use PhpPact\Consumer\Matcher\Model\MatcherInterface;

/**
* Match if the value is a null value (this is content specific, for JSON will match a JSON null)
*/
class NullValue implements MatcherInterface
{
/**
* @return array<string, string>
*/
public function jsonSerialize(): array
{
return [
'pact:matcher:type' => $this->getType(),
];
}

public function getType(): string
{
return 'null';
}
}
18 changes: 18 additions & 0 deletions tests/PhpPact/Consumer/Matcher/Matchers/NullValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace PhpPactTest\Consumer\Matcher\Matchers;

use PhpPact\Consumer\Matcher\Matchers\NullValue;
use PHPUnit\Framework\TestCase;

class NullValueTest extends TestCase
{
public function testSerialize(): void
{
$null = new NullValue();
$this->assertSame(
'{"pact:matcher:type":"null"}',
json_encode($null)
);
}
}

0 comments on commit 6b895c0

Please sign in to comment.