diff --git a/src/PhpPact/Consumer/Matcher/Matchers/AbstractDateTime.php b/src/PhpPact/Consumer/Matcher/Matchers/AbstractDateTime.php new file mode 100644 index 00000000..47c4ec28 --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Matchers/AbstractDateTime.php @@ -0,0 +1,23 @@ + + */ + protected function getAttributesData(): array + { + return ['format' => $this->format]; + } + + protected function getValue(): ?string + { + return $this->value; + } +} diff --git a/src/PhpPact/Consumer/Matcher/Matchers/Date.php b/src/PhpPact/Consumer/Matcher/Matchers/Date.php new file mode 100644 index 00000000..67ca1e82 --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Matchers/Date.php @@ -0,0 +1,28 @@ +setGenerator(new DateGenerator($format)); + } + parent::__construct($format, $value); + } + + public function getType(): string + { + return 'date'; + } +} diff --git a/tests/PhpPact/Consumer/Matcher/Matchers/DateTest.php b/tests/PhpPact/Consumer/Matcher/Matchers/DateTest.php new file mode 100644 index 00000000..95a4b0aa --- /dev/null +++ b/tests/PhpPact/Consumer/Matcher/Matchers/DateTest.php @@ -0,0 +1,24 @@ +matcher = new Date(); + } + + /** + * @testWith [null, "{\"pact:matcher:type\":\"date\",\"pact:generator:type\":\"Date\",\"format\":\"yyyy-MM-dd\"}"] + * ["1995-02-04", "{\"pact:matcher:type\":\"date\",\"format\":\"yyyy-MM-dd\",\"value\":\"1995-02-04\"}"] + */ + public function testSerialize(?string $value, string $json): void + { + $format = 'yyyy-MM-dd'; + $this->matcher = new Date($format, $value); + $this->assertSame($json, json_encode($this->matcher)); + } +}