diff --git a/compatibility-suite/tests/Context/V3/Message/ConsumerContext.php b/compatibility-suite/tests/Context/V3/Message/ConsumerContext.php index a50dfc15..7ddfece2 100644 --- a/compatibility-suite/tests/Context/V3/Message/ConsumerContext.php +++ b/compatibility-suite/tests/Context/V3/Message/ConsumerContext.php @@ -5,7 +5,7 @@ use Behat\Behat\Context\Context; use Behat\Gherkin\Node\TableNode; use Exception; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\MessageBuilder; use PhpPact\Standalone\PactMessage\PactMessageConfig; use PhpPactTest\CompatibilitySuite\Constant\Path; @@ -41,7 +41,7 @@ public function __construct( ->setProvider(PactPath::PROVIDER) ->setPactDir(Path::PACTS_PATH) ->setPactSpecificationVersion($specificationVersion) - ->setPactFileWriteMode(PactConfigInterface::MODE_OVERWRITE); + ->setPactFileWriteMode(WriteMode::OVERWRITE); $this->builder = new MessageBuilder($config); } diff --git a/compatibility-suite/tests/Context/V4/CombinedContext.php b/compatibility-suite/tests/Context/V4/CombinedContext.php index d0fbb9f1..898e3ce2 100644 --- a/compatibility-suite/tests/Context/V4/CombinedContext.php +++ b/compatibility-suite/tests/Context/V4/CombinedContext.php @@ -3,7 +3,7 @@ namespace PhpPactTest\CompatibilitySuite\Context\V4; use Behat\Behat\Context\Context; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\Model\Message; use PhpPactTest\CompatibilitySuite\Model\PactPath; use PhpPactTest\CompatibilitySuite\Service\InteractionBuilderInterface; @@ -51,10 +51,10 @@ public function aMessageInteractionIsBeingDefinedForAConsumerTest(): void */ public function thePactFileForTheTestIsGenerated(): void { - $this->pactWriter->write($this->id, $this->pactPath, PactConfigInterface::MODE_MERGE); + $this->pactWriter->write($this->id, $this->pactPath, WriteMode::MERGE); $message = new Message(); $message->setDescription('message interaction'); - $this->messagePactWriter->write($message, $this->pactPath, PactConfigInterface::MODE_MERGE); + $this->messagePactWriter->write($message, $this->pactPath, WriteMode::MERGE); } /** diff --git a/compatibility-suite/tests/Service/MessagePactWriter.php b/compatibility-suite/tests/Service/MessagePactWriter.php index 36328bf9..59d7b4af 100644 --- a/compatibility-suite/tests/Service/MessagePactWriter.php +++ b/compatibility-suite/tests/Service/MessagePactWriter.php @@ -2,7 +2,7 @@ namespace PhpPactTest\CompatibilitySuite\Service; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\Factory\MessageDriverFactory; use PhpPact\Consumer\Model\Message; use PhpPact\Standalone\MockService\MockServerConfig; @@ -17,7 +17,7 @@ public function __construct( ) { } - public function write(Message $message, PactPath $pactPath, string $mode = PactConfigInterface::MODE_OVERWRITE): void + public function write(Message $message, PactPath $pactPath, WriteMode $mode = WriteMode::OVERWRITE): void { $config = new MockServerConfig(); $config diff --git a/compatibility-suite/tests/Service/MessagePactWriterInterface.php b/compatibility-suite/tests/Service/MessagePactWriterInterface.php index 59d3ffd5..2c62dc5b 100644 --- a/compatibility-suite/tests/Service/MessagePactWriterInterface.php +++ b/compatibility-suite/tests/Service/MessagePactWriterInterface.php @@ -2,11 +2,11 @@ namespace PhpPactTest\CompatibilitySuite\Service; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\Model\Message; use PhpPactTest\CompatibilitySuite\Model\PactPath; interface MessagePactWriterInterface { - public function write(Message $message, PactPath $pactPath, string $mode = PactConfigInterface::MODE_OVERWRITE): void; + public function write(Message $message, PactPath $pactPath, WriteMode $mode = WriteMode::OVERWRITE): void; } diff --git a/compatibility-suite/tests/Service/PactWriter.php b/compatibility-suite/tests/Service/PactWriter.php index f4580229..c85c1e55 100644 --- a/compatibility-suite/tests/Service/PactWriter.php +++ b/compatibility-suite/tests/Service/PactWriter.php @@ -2,7 +2,7 @@ namespace PhpPactTest\CompatibilitySuite\Service; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\Factory\InteractionDriverFactory; use PhpPact\Standalone\MockService\MockServerConfig; use PhpPactTest\CompatibilitySuite\Constant\Path; @@ -16,7 +16,7 @@ public function __construct( ) { } - public function write(int $id, PactPath $pactPath, string $mode = PactConfigInterface::MODE_OVERWRITE): void + public function write(int $id, PactPath $pactPath, WriteMode $mode = WriteMode::OVERWRITE): void { $config = new MockServerConfig(); $config diff --git a/compatibility-suite/tests/Service/PactWriterInterface.php b/compatibility-suite/tests/Service/PactWriterInterface.php index 482fbdc4..528fb930 100644 --- a/compatibility-suite/tests/Service/PactWriterInterface.php +++ b/compatibility-suite/tests/Service/PactWriterInterface.php @@ -2,10 +2,10 @@ namespace PhpPactTest\CompatibilitySuite\Service; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPactTest\CompatibilitySuite\Model\PactPath; interface PactWriterInterface { - public function write(int $id, PactPath $pactPath, string $mode = PactConfigInterface::MODE_OVERWRITE): void; + public function write(int $id, PactPath $pactPath, WriteMode $mode = WriteMode::OVERWRITE): void; } diff --git a/compatibility-suite/tests/Service/Server.php b/compatibility-suite/tests/Service/Server.php index dfab8e48..c4580f8b 100644 --- a/compatibility-suite/tests/Service/Server.php +++ b/compatibility-suite/tests/Service/Server.php @@ -2,7 +2,7 @@ namespace PhpPactTest\CompatibilitySuite\Service; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\Driver\Interaction\InteractionDriverInterface; use PhpPact\Consumer\Factory\InteractionDriverFactory; use PhpPact\Standalone\MockService\MockServerConfig; @@ -30,7 +30,7 @@ public function __construct( ->setProvider(PactPath::PROVIDER) ->setPactDir(Path::PACTS_PATH) ->setPactSpecificationVersion($specificationVersion) - ->setPactFileWriteMode(PactConfigInterface::MODE_OVERWRITE); + ->setPactFileWriteMode(WriteMode::OVERWRITE); if ($level = \getenv('PACT_LOGLEVEL')) { $this->config->setLogLevel($level); diff --git a/compatibility-suite/tests/Service/SyncMessagePactWriter.php b/compatibility-suite/tests/Service/SyncMessagePactWriter.php index 6def54d0..71ef4213 100644 --- a/compatibility-suite/tests/Service/SyncMessagePactWriter.php +++ b/compatibility-suite/tests/Service/SyncMessagePactWriter.php @@ -2,7 +2,7 @@ namespace PhpPactTest\CompatibilitySuite\Service; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\Model\Message; use PhpPact\Standalone\MockService\MockServerConfig; use PhpPact\SyncMessage\Factory\SyncMessageDriverFactory; @@ -16,7 +16,7 @@ public function __construct( ) { } - public function write(Message $message, PactPath $pactPath, string $mode = PactConfigInterface::MODE_OVERWRITE): void + public function write(Message $message, PactPath $pactPath, WriteMode $mode = WriteMode::OVERWRITE): void { $config = new MockServerConfig(); $config diff --git a/compatibility-suite/tests/Service/SyncMessagePactWriterInterface.php b/compatibility-suite/tests/Service/SyncMessagePactWriterInterface.php index 8ef29920..ebdbb95f 100644 --- a/compatibility-suite/tests/Service/SyncMessagePactWriterInterface.php +++ b/compatibility-suite/tests/Service/SyncMessagePactWriterInterface.php @@ -2,11 +2,11 @@ namespace PhpPactTest\CompatibilitySuite\Service; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\Model\Message; use PhpPactTest\CompatibilitySuite\Model\PactPath; interface SyncMessagePactWriterInterface { - public function write(Message $message, PactPath $pactPath, string $mode = PactConfigInterface::MODE_OVERWRITE): void; + public function write(Message $message, PactPath $pactPath, WriteMode $mode = WriteMode::OVERWRITE): void; } diff --git a/src/PhpPact/Config/Enum/WriteMode.php b/src/PhpPact/Config/Enum/WriteMode.php new file mode 100644 index 00000000..568173d9 --- /dev/null +++ b/src/PhpPact/Config/Enum/WriteMode.php @@ -0,0 +1,15 @@ +pactFileWriteMode; } @@ -163,16 +165,19 @@ public function getPactFileWriteMode(): string /** * {@inheritdoc} */ - public function setPactFileWriteMode(string $pactFileWriteMode): self + public function setPactFileWriteMode(string|WriteMode $pactFileWriteMode): self { - $options = [self::MODE_OVERWRITE, self::MODE_MERGE]; - - if (!\in_array($pactFileWriteMode, $options)) { - $implodedOptions = \implode(', ', $options); - - throw new \InvalidArgumentException("Invalid PhpPact File Write Mode, value must be one of the following: {$implodedOptions}."); + if (is_string($pactFileWriteMode)) { + try { + $pactFileWriteMode = WriteMode::from($pactFileWriteMode); + } catch (\Throwable $th) { + $all = implode(', ', array_map( + fn (WriteMode $mode) => $mode->value, + WriteMode::cases() + )); + throw new InvalidWriteModeException(sprintf("Mode '%s' is not supported. Supported modes are: %s", $pactFileWriteMode, $all)); + } } - $this->pactFileWriteMode = $pactFileWriteMode; return $this; diff --git a/src/PhpPact/Config/PactConfigInterface.php b/src/PhpPact/Config/PactConfigInterface.php index 71f76b3c..f0383bba 100644 --- a/src/PhpPact/Config/PactConfigInterface.php +++ b/src/PhpPact/Config/PactConfigInterface.php @@ -2,7 +2,8 @@ namespace PhpPact\Config; -use InvalidArgumentException; +use PhpPact\Config\Exception\InvalidWriteModeException; +use PhpPact\Config\Enum\WriteMode; use UnexpectedValueException; /** @@ -12,9 +13,16 @@ interface PactConfigInterface { public const DEFAULT_SPECIFICATION_VERSION = '3.0.0'; + /** + * @deprecated Use WriteMode::OVERWRITE instead + */ public const MODE_OVERWRITE = 'overwrite'; + /** + * @deprecated Use WriteMode::MERGE instead + */ public const MODE_MERGE = 'merge'; + public function getConsumer(): string; /** @@ -65,15 +73,10 @@ public function getLogLevel(): ?string; public function setLogLevel(string $logLevel): self; - /** - * @return string 'merge' or 'overwrite' merge means that interactions are added and overwrite means that the entire file is overwritten - */ - public function getPactFileWriteMode(): string; + public function getPactFileWriteMode(): WriteMode; /** - * @param string $pactFileWriteMode 'merge' or 'overwrite' merge means that interactions are added and overwrite means that the entire file is overwritten - * - * @throws InvalidArgumentException If mode is incorrect. + * @throws InvalidWriteModeException If mode is incorrect. */ - public function setPactFileWriteMode(string $pactFileWriteMode): self; + public function setPactFileWriteMode(string|WriteMode $pactFileWriteMode): self; } diff --git a/src/PhpPact/Consumer/Driver/Pact/PactDriver.php b/src/PhpPact/Consumer/Driver/Pact/PactDriver.php index 0e533bdb..e2de57df 100644 --- a/src/PhpPact/Consumer/Driver/Pact/PactDriver.php +++ b/src/PhpPact/Consumer/Driver/Pact/PactDriver.php @@ -3,6 +3,7 @@ namespace PhpPact\Consumer\Driver\Pact; use Composer\Semver\Comparator; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Config\PactConfigInterface; use PhpPact\Consumer\Driver\Exception\MissingPactException; use PhpPact\Consumer\Driver\Exception\PactFileNotWrittenException; @@ -34,7 +35,7 @@ public function writePact(): void $error = $this->client->pactHandleWriteFile( $this->getPact()->handle, $this->config->getPactDir(), - $this->config->getPactFileWriteMode() === PactConfigInterface::MODE_OVERWRITE + $this->config->getPactFileWriteMode() === WriteMode::OVERWRITE ); if ($error) { throw new PactFileNotWrittenException($error); diff --git a/src/PhpPact/Consumer/Matcher/Enum/HttpStatus.php b/src/PhpPact/Consumer/Matcher/Enum/HttpStatus.php new file mode 100644 index 00000000..68d5d84e --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Enum/HttpStatus.php @@ -0,0 +1,29 @@ + new Range(100, 199), + self::SUCCESS => new Range(200, 299), + self::REDIRECT => new Range(300, 399), + self::CLIENT_ERROR => new Range(400, 499), + self::SERVER_ERROR => new Range(500, 599), + self::NON_ERROR => new Range(100, 399), + self::ERROR => new Range(400, 599), + }; + } +} diff --git a/src/PhpPact/Consumer/Matcher/Enum/UuidFormat.php b/src/PhpPact/Consumer/Matcher/Enum/UuidFormat.php new file mode 100644 index 00000000..1a229075 --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Enum/UuidFormat.php @@ -0,0 +1,11 @@ + $status->value, + UuidFormat::cases() + )); + throw new InvalidUuidFormatException(sprintf('Format %s is not supported. Supported formats are: %s', $format, $all)); + } } + $this->format = $format; } public function getType(): string @@ -44,7 +61,7 @@ public function getType(): string protected function getAttributesData(): array { return $this->format !== null ? [ - 'format' => $this->format, + 'format' => $this->format->value, ] : []; } } diff --git a/src/PhpPact/Consumer/Matcher/HttpStatus.php b/src/PhpPact/Consumer/Matcher/HttpStatus.php index 527bd13e..2fb61069 100644 --- a/src/PhpPact/Consumer/Matcher/HttpStatus.php +++ b/src/PhpPact/Consumer/Matcher/HttpStatus.php @@ -2,6 +2,9 @@ namespace PhpPact\Consumer\Matcher; +/** + * @deprecated Use PhpPact\Consumer\Matcher\Enum\HttpStatus instead + */ class HttpStatus { public const INFORMATION = 'info'; @@ -11,20 +14,4 @@ class HttpStatus public const SERVER_ERROR = 'serverError'; public const NON_ERROR = 'nonError'; public const ERROR = 'error'; - - /** - * @return array - */ - public static function all(): array - { - return [ - self::INFORMATION, - self::SUCCESS, - self::REDIRECT, - self::CLIENT_ERROR, - self::SERVER_ERROR, - self::NON_ERROR, - self::ERROR, - ]; - } } diff --git a/src/PhpPact/Consumer/Matcher/Matcher.php b/src/PhpPact/Consumer/Matcher/Matcher.php index 82b903f8..92e8629f 100644 --- a/src/PhpPact/Consumer/Matcher/Matcher.php +++ b/src/PhpPact/Consumer/Matcher/Matcher.php @@ -2,6 +2,7 @@ namespace PhpPact\Consumer\Matcher; +use PhpPact\Consumer\Matcher\Enum\HttpStatus; use PhpPact\Consumer\Matcher\Exception\MatcherException; use PhpPact\Consumer\Matcher\Generators\MockServerURL; use PhpPact\Consumer\Matcher\Generators\ProviderState; @@ -386,7 +387,7 @@ public function semver(string $value): MatcherInterface /** * Matches the response status code. */ - public function statusCode(string $status, ?int $value = null): MatcherInterface + public function statusCode(string|HttpStatus $status, ?int $value = null): MatcherInterface { return $this->withFormatter(new StatusCode($status, $value)); } diff --git a/src/PhpPact/Consumer/Matcher/Matchers/StatusCode.php b/src/PhpPact/Consumer/Matcher/Matchers/StatusCode.php index 8d1b5226..0d995008 100644 --- a/src/PhpPact/Consumer/Matcher/Matchers/StatusCode.php +++ b/src/PhpPact/Consumer/Matcher/Matchers/StatusCode.php @@ -2,11 +2,11 @@ namespace PhpPact\Consumer\Matcher\Matchers; +use PhpPact\Consumer\Matcher\Enum\HttpStatus; use PhpPact\Consumer\Matcher\Exception\InvalidHttpStatusException; use PhpPact\Consumer\Matcher\Exception\MatcherNotSupportedException; use PhpPact\Consumer\Matcher\Formatters\Json\HasGeneratorFormatter; use PhpPact\Consumer\Matcher\Generators\RandomInt; -use PhpPact\Consumer\Matcher\HttpStatus; use PhpPact\Consumer\Matcher\Model\ExpressionFormatterInterface; use PhpPact\Consumer\Matcher\Model\JsonFormatterInterface; @@ -15,25 +15,27 @@ */ class StatusCode extends GeneratorAwareMatcher { - public function __construct(private string $status, private ?int $value = null) + private HttpStatus $status; + + public function __construct(string|HttpStatus $status, private ?int $value = null) { - if (!in_array($status, HttpStatus::all())) { - throw new InvalidHttpStatusException(sprintf("Status '%s' is not supported. Supported status are: %s", $status, implode(', ', HttpStatus::all()))); + if (is_string($status)) { + try { + $status = HttpStatus::from($status); + } catch (\Throwable $th) { + $all = implode(', ', array_map( + fn (HttpStatus $status) => $status->value, + HttpStatus::cases() + )); + throw new InvalidHttpStatusException(sprintf("Status '%s' is not supported. Supported status are: %s", $status, $all)); + } } + $this->status = $status; if ($value === null) { - [$min, $max] = match($status) { - HttpStatus::INFORMATION => [100, 199], - HttpStatus::SUCCESS => [200, 299], - HttpStatus::REDIRECT => [300, 399], - HttpStatus::CLIENT_ERROR => [400, 499], - HttpStatus::SERVER_ERROR => [500, 599], - HttpStatus::NON_ERROR => [100, 399], - HttpStatus::ERROR => [400, 599], - default => [100, 199], // Can't happen, just to make PHPStan happy - }; + $range = $status->range(); - $this->setGenerator(new RandomInt($min, $max)); + $this->setGenerator(new RandomInt($range->min, $range->max)); } parent::__construct(); } @@ -48,7 +50,7 @@ public function getType(): string */ protected function getAttributesData(): array { - return ['status' => $this->status]; + return ['status' => $this->status->value]; } public function getValue(): ?int diff --git a/src/PhpPact/Consumer/Matcher/Model/Range.php b/src/PhpPact/Consumer/Matcher/Model/Range.php new file mode 100644 index 00000000..871b9f66 --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Model/Range.php @@ -0,0 +1,10 @@ +client->writePactFile( $this->config->getPort(), $this->config->getPactDir(), - $this->config->getPactFileWriteMode() === PactConfigInterface::MODE_OVERWRITE + $this->config->getPactFileWriteMode() === WriteMode::OVERWRITE ); if ($error) { throw new MockServerPactFileNotWrittenException($error); diff --git a/tests/PhpPact/Config/PactConfigTest.php b/tests/PhpPact/Config/PactConfigTest.php index ceb7da85..661e9dd6 100644 --- a/tests/PhpPact/Config/PactConfigTest.php +++ b/tests/PhpPact/Config/PactConfigTest.php @@ -2,6 +2,8 @@ namespace PhpPactTest\Config; +use PhpPact\Config\Enum\WriteMode; +use PhpPact\Config\Exception\InvalidWriteModeException; use PhpPact\Config\PactConfig; use PhpPact\Config\PactConfigInterface; use PHPUnit\Framework\Attributes\TestWith; @@ -41,7 +43,7 @@ public function testSetters(): void static::assertSame($pactSpecificationVersion, $this->config->getPactSpecificationVersion()); static::assertSame($log, $this->config->getLog()); static::assertSame($logLevel, $this->config->getLogLevel()); - static::assertSame($pactFileWriteMode, $this->config->getPactFileWriteMode()); + static::assertSame(WriteMode::tryFrom($pactFileWriteMode), $this->config->getPactFileWriteMode()); } public function testInvalidPactSpecificationVersion(): void @@ -71,8 +73,8 @@ public function testLogLevel(string $logLevel, ?string $result): void public function testInvalidPactFileWriteMode(): void { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage("Invalid PhpPact File Write Mode, value must be one of the following: overwrite, merge."); + $this->expectException(InvalidWriteModeException::class); + $this->expectExceptionMessage("Mode 'APPEND' is not supported. Supported modes are: overwrite, merge"); $this->config->setPactFileWriteMode('APPEND'); } } diff --git a/tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php b/tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php index f11df3a4..9e3e81cd 100644 --- a/tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php +++ b/tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php @@ -2,6 +2,7 @@ namespace PhpPactTest\Consumer\Driver\Pact; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Config\PactConfigInterface; use PhpPact\Consumer\Driver\Exception\MissingPactException; use PhpPact\Consumer\Driver\Exception\PactFileNotWrittenException; @@ -110,17 +111,17 @@ public function testGetPactWithoutPact(): void $this->driver->getPact(); } - #[TestWith([0, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([1, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([2, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([3, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([4, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([0, PactConfigInterface::MODE_MERGE])] - #[TestWith([1, PactConfigInterface::MODE_MERGE])] - #[TestWith([2, PactConfigInterface::MODE_MERGE])] - #[TestWith([3, PactConfigInterface::MODE_MERGE])] - #[TestWith([4, PactConfigInterface::MODE_MERGE])] - public function testWritePact(int $error, string $writeMode): void + #[TestWith([0, WriteMode::OVERWRITE])] + #[TestWith([1, WriteMode::OVERWRITE])] + #[TestWith([2, WriteMode::OVERWRITE])] + #[TestWith([3, WriteMode::OVERWRITE])] + #[TestWith([4, WriteMode::OVERWRITE])] + #[TestWith([0, WriteMode::MERGE])] + #[TestWith([1, WriteMode::MERGE])] + #[TestWith([2, WriteMode::MERGE])] + #[TestWith([3, WriteMode::MERGE])] + #[TestWith([4, WriteMode::MERGE])] + public function testWritePact(int $error, WriteMode $writeMode): void { $this->assertConfig(null, '1.0.0'); $this->config @@ -133,7 +134,7 @@ public function testWritePact(int $error, string $writeMode): void ->willReturn($writeMode); $this->expectsNewPact($this->consumer, $this->provider, $this->pactHandle); $this->expectsWithSpecification($this->pactHandle, self::SPEC_V1, true); - $this->expectsPactHandleWriteFile($this->pactHandle, $this->pactDir, $writeMode === PactConfigInterface::MODE_OVERWRITE, $error); + $this->expectsPactHandleWriteFile($this->pactHandle, $this->pactDir, $writeMode === WriteMode::OVERWRITE, $error); $this->driver->setUp(); if ($error) { $this->expectException(PactFileNotWrittenException::class); diff --git a/tests/PhpPact/Consumer/Matcher/MatcherTest.php b/tests/PhpPact/Consumer/Matcher/MatcherTest.php index 602c1ef1..e76c7845 100644 --- a/tests/PhpPact/Consumer/Matcher/MatcherTest.php +++ b/tests/PhpPact/Consumer/Matcher/MatcherTest.php @@ -2,7 +2,7 @@ namespace PhpPactTest\Consumer\Matcher; -use PhpPact\Consumer\Matcher\Exception\MatcherException; +use PhpPact\Consumer\Matcher\Enum\HttpStatus; use PhpPact\Consumer\Matcher\Exception\MatcherNotSupportedException; use PhpPact\Consumer\Matcher\Formatters\Expression\RegexFormatter; use PhpPact\Consumer\Matcher\Formatters\Json\HasGeneratorFormatter; @@ -10,7 +10,6 @@ use PhpPact\Consumer\Matcher\Generators\ProviderState; use PhpPact\Consumer\Matcher\Generators\RandomHexadecimal; use PhpPact\Consumer\Matcher\Generators\Uuid; -use PhpPact\Consumer\Matcher\HttpStatus; use PhpPact\Consumer\Matcher\Matcher; use PhpPact\Consumer\Matcher\Matchers\ArrayContains; use PhpPact\Consumer\Matcher\Matchers\Boolean; diff --git a/tests/PhpPact/Consumer/Service/MockServerTest.php b/tests/PhpPact/Consumer/Service/MockServerTest.php index b07f7493..4b16c0af 100644 --- a/tests/PhpPact/Consumer/Service/MockServerTest.php +++ b/tests/PhpPact/Consumer/Service/MockServerTest.php @@ -2,7 +2,7 @@ namespace PhpPactTest\Consumer\Service; -use PhpPact\Config\PactConfigInterface; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Consumer\Driver\Pact\PactDriverInterface; use PhpPact\Consumer\Exception\MockServerPactFileNotWrittenException; use PhpPact\Consumer\Model\Pact\Pact; @@ -77,22 +77,22 @@ public function testVerify(bool $matched): void $this->assertSame('', $result->mismatches); } - #[TestWith([0, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([1, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([2, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([3, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([4, PactConfigInterface::MODE_OVERWRITE])] - #[TestWith([0, PactConfigInterface::MODE_MERGE])] - #[TestWith([1, PactConfigInterface::MODE_MERGE])] - #[TestWith([2, PactConfigInterface::MODE_MERGE])] - #[TestWith([3, PactConfigInterface::MODE_MERGE])] - #[TestWith([4, PactConfigInterface::MODE_MERGE])] - public function testWritePact(int $error, string $writeMode): void + #[TestWith([0, WriteMode::OVERWRITE])] + #[TestWith([1, WriteMode::OVERWRITE])] + #[TestWith([2, WriteMode::OVERWRITE])] + #[TestWith([3, WriteMode::OVERWRITE])] + #[TestWith([4, WriteMode::OVERWRITE])] + #[TestWith([0, WriteMode::MERGE])] + #[TestWith([1, WriteMode::MERGE])] + #[TestWith([2, WriteMode::MERGE])] + #[TestWith([3, WriteMode::MERGE])] + #[TestWith([4, WriteMode::MERGE])] + public function testWritePact(int $error, WriteMode $writeMode): void { $this->config->setPort($this->port); $this->config->setPactDir($this->pactDir); $this->config->setPactFileWriteMode($writeMode); - $this->expectsWritePactFile($this->port, $this->pactDir, $writeMode === PactConfigInterface::MODE_OVERWRITE, $error, true); + $this->expectsWritePactFile($this->port, $this->pactDir, $writeMode === WriteMode::OVERWRITE, $error, true); if ($error) { $this->expectException(MockServerPactFileNotWrittenException::class); $this->expectExceptionMessage(match ($error) { diff --git a/tests/PhpPact/Standalone/MockServer/MockServerConfigTest.php b/tests/PhpPact/Standalone/MockServer/MockServerConfigTest.php index b8f02c7f..583005cc 100644 --- a/tests/PhpPact/Standalone/MockServer/MockServerConfigTest.php +++ b/tests/PhpPact/Standalone/MockServer/MockServerConfigTest.php @@ -2,6 +2,7 @@ namespace PhpPactTest\Standalone\MockServer; +use PhpPact\Config\Enum\WriteMode; use PhpPact\Standalone\MockService\MockServerConfig; use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; @@ -38,7 +39,7 @@ public function testSetters(): void static::assertSame($provider, $subject->getProvider()); static::assertSame($consumer, $subject->getConsumer()); static::assertSame($pactDir, $subject->getPactDir()); - static::assertSame($pactFileWriteMode, $subject->getPactFileWriteMode()); + static::assertSame(WriteMode::tryFrom($pactFileWriteMode), $subject->getPactFileWriteMode()); static::assertSame($log, $subject->getLog()); static::assertSame($logLevel, $subject->getLogLevel()); static::assertSame($pactSpecificationVersion, $subject->getPactSpecificationVersion());