Skip to content

Commit

Permalink
Merge pull request pact-foundation#588 from tienvx/use-intersection-t…
Browse files Browse the repository at this point in the history
…ypes-feature

refactor: Use intersection types
  • Loading branch information
tienvx authored May 2, 2024
2 parents 0a03f3f + 8c90b3a commit 2100176
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
9 changes: 1 addition & 8 deletions src/PhpPact/Consumer/Matcher/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions tests/PhpPact/Consumer/Matcher/MatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2100176

Please sign in to comment.