From 8c90b3aa3881fd31da54a5c67aa6d453f10c8bf8 Mon Sep 17 00:00:00 2001 From: tienvx Date: Thu, 2 May 2024 08:30:39 +0700 Subject: [PATCH] refactor: Use intersection types --- src/PhpPact/Consumer/Matcher/Matcher.php | 9 +-------- tests/PhpPact/Consumer/Matcher/MatcherTest.php | 8 -------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/PhpPact/Consumer/Matcher/Matcher.php b/src/PhpPact/Consumer/Matcher/Matcher.php index fd3ae6ae..b2feea73 100644 --- a/src/PhpPact/Consumer/Matcher/Matcher.php +++ b/src/PhpPact/Consumer/Matcher/Matcher.php @@ -3,7 +3,6 @@ namespace PhpPact\Consumer\Matcher; use PhpPact\Consumer\Matcher\Exception\MatcherException; -use PhpPact\Consumer\Matcher\Exception\MatcherNotSupportedException; use PhpPact\Consumer\Matcher\Generators\MockServerURL; use PhpPact\Consumer\Matcher\Generators\ProviderState; use PhpPact\Consumer\Matcher\Generators\RandomHexadecimal; @@ -334,15 +333,9 @@ public function string(?string $value = null): MatcherInterface /** * Generates a value that is looked up from the provider state context using the given expression - * - * @throws MatcherNotSupportedException */ - public function fromProviderState(MatcherInterface $matcher, string $expression): MatcherInterface + public function fromProviderState(MatcherInterface&GeneratorAwareInterface $matcher, string $expression): MatcherInterface { - if (!$matcher instanceof GeneratorAwareInterface) { - throw new MatcherNotSupportedException(sprintf("Matcher '%s' must be generator aware", $matcher->getType())); - } - $matcher->setGenerator(new ProviderState($expression)); return $matcher; diff --git a/tests/PhpPact/Consumer/Matcher/MatcherTest.php b/tests/PhpPact/Consumer/Matcher/MatcherTest.php index c585d115..aed021ab 100644 --- a/tests/PhpPact/Consumer/Matcher/MatcherTest.php +++ b/tests/PhpPact/Consumer/Matcher/MatcherTest.php @@ -3,7 +3,6 @@ namespace PhpPactTest\Consumer\Matcher; use PhpPact\Consumer\Matcher\Exception\MatcherException; -use PhpPact\Consumer\Matcher\Exception\MatcherNotSupportedException; use PhpPact\Consumer\Matcher\Formatters\MinimalFormatter; use PhpPact\Consumer\Matcher\Formatters\ValueOptionalFormatter; use PhpPact\Consumer\Matcher\Generators\MockServerURL; @@ -252,13 +251,6 @@ public function testString(): void $this->assertInstanceOf(StringValue::class, $this->matcher->string('test string')); } - public function testFromProviderStateMatcherNotSupport(): void - { - $this->expectException(MatcherNotSupportedException::class); - $this->expectExceptionMessage("Matcher 'type' must be generator aware"); - $this->matcher->fromProviderState(new Type('text'), '${text}'); - } - public function testFromProviderState(): void { $uuid = $this->matcher->uuid();