From 3b3c899ebcbba11dfb1e3fe9efc884130cf2232c Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Fri, 15 Dec 2023 10:26:17 +0700 Subject: [PATCH] refactor: Add ContentType matcher class --- .../Consumer/Matcher/Matchers/ContentType.php | 31 +++++++++++++++++++ .../Matcher/Matchers/ContentTypeTest.php | 18 +++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/PhpPact/Consumer/Matcher/Matchers/ContentType.php create mode 100644 tests/PhpPact/Consumer/Matcher/Matchers/ContentTypeTest.php diff --git a/src/PhpPact/Consumer/Matcher/Matchers/ContentType.php b/src/PhpPact/Consumer/Matcher/Matchers/ContentType.php new file mode 100644 index 00000000..052e6e41 --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Matchers/ContentType.php @@ -0,0 +1,31 @@ + + */ + public function jsonSerialize(): array + { + return [ + 'value' => $this->contentType, + 'pact:matcher:type' => $this->getType(), + ]; + } + + public function getType(): string + { + return 'contentType'; + } +} diff --git a/tests/PhpPact/Consumer/Matcher/Matchers/ContentTypeTest.php b/tests/PhpPact/Consumer/Matcher/Matchers/ContentTypeTest.php new file mode 100644 index 00000000..4b837779 --- /dev/null +++ b/tests/PhpPact/Consumer/Matcher/Matchers/ContentTypeTest.php @@ -0,0 +1,18 @@ +assertSame( + '{"value":"text\/csv","pact:matcher:type":"contentType"}', + json_encode($contentType) + ); + } +}