-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Matchers; | ||
|
||
use PhpPact\Consumer\Matcher\Model\MatcherInterface; | ||
|
||
/** | ||
* This executes a type based match against the values, that is, they are equal if they are the same type. | ||
*/ | ||
class Type implements MatcherInterface | ||
{ | ||
/** | ||
* @param object|array<mixed>|string|float|int|bool|null $value | ||
*/ | ||
public function __construct(private object|array|string|float|int|bool|null $value) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'pact:matcher:type' => $this->getType(), | ||
'value' => $this->value, | ||
]; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return 'type'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace PhpPactTest\Consumer\Matcher\Matchers; | ||
|
||
use PhpPact\Consumer\Matcher\Matchers\Type; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TypeTest extends TestCase | ||
{ | ||
public function testSerialize(): void | ||
{ | ||
$value = (object) ['key' => 'value']; | ||
$object = new Type($value); | ||
$this->assertSame( | ||
'{"pact:matcher:type":"type","value":{"key":"value"}}', | ||
json_encode($object) | ||
); | ||
} | ||
} |