diff --git a/src/PhpPact/Consumer/Matcher/Exception/InvalidRegexException.php b/src/PhpPact/Consumer/Matcher/Exception/InvalidRegexException.php deleted file mode 100644 index 97b72f6d..00000000 --- a/src/PhpPact/Consumer/Matcher/Exception/InvalidRegexException.php +++ /dev/null @@ -1,7 +0,0 @@ -setGenerator(new RegexGenerator($this->regex)); - } else { - $this->validateRegex(); } parent::__construct(); } - /** - * @todo Use json_validate() - */ - private function validateRegex(): void - { - foreach ((array) $this->values as $value) { - $result = preg_match("/$this->regex/", $value); - - if ($result !== 1) { - $errorCode = preg_last_error(); - - throw new InvalidRegexException("The value '{$value}' doesn't match pattern '{$this->regex}'. Failed with error code {$errorCode}."); - } - } - } - public function formatJson(): Attributes { return $this->mergeJson(new Attributes([ diff --git a/tests/PhpPact/Consumer/Matcher/Matchers/EachValueTest.php b/tests/PhpPact/Consumer/Matcher/Matchers/EachValueTest.php index 98a16879..72eb7646 100644 --- a/tests/PhpPact/Consumer/Matcher/Matchers/EachValueTest.php +++ b/tests/PhpPact/Consumer/Matcher/Matchers/EachValueTest.php @@ -55,7 +55,7 @@ public function testFormatJson(): void "value": null } ] - } + } JSON, $jsonEncoded ); diff --git a/tests/PhpPact/Consumer/Matcher/Matchers/RegexTest.php b/tests/PhpPact/Consumer/Matcher/Matchers/RegexTest.php index 9306fd84..3a82f0f5 100644 --- a/tests/PhpPact/Consumer/Matcher/Matchers/RegexTest.php +++ b/tests/PhpPact/Consumer/Matcher/Matchers/RegexTest.php @@ -2,7 +2,6 @@ namespace PhpPactTest\Consumer\Matcher\Matchers; -use PhpPact\Consumer\Matcher\Exception\InvalidRegexException; use PhpPact\Consumer\Matcher\Exception\InvalidValueException; use PhpPact\Consumer\Matcher\Formatters\Expression\ExpressionFormatter; use PhpPact\Consumer\Matcher\Matchers\Regex; @@ -14,17 +13,6 @@ class RegexTest extends TestCase { private string $regex = '\d+'; - #[TestWith(['number', true])] - #[TestWith(['integer', false])] - public function testInvalidRegex(string $value, bool $isArray): void - { - $values = $isArray ? [$value] : $value; - $this->expectException(InvalidRegexException::class); - $value = is_array($values) ? $values[0] : $values; - $this->expectExceptionMessage("The value '{$value}' doesn't match pattern '{$this->regex}'. Failed with error code 0."); - new Regex($this->regex, $values); - } - /** * @param string|string[]|null $values */