From 74642583b5e9800cd681cce66b429ef95337af2e Mon Sep 17 00:00:00 2001 From: upstream Date: Thu, 3 Sep 2026 14:28:48 +0200 Subject: [PATCH] Upstream webmozarts/assert state of the touched files before 381c97d823 --- src/Assert.php | 10 +------- tests/AssertTest.php | 61 -------------------------------------------- 2 files changed, 1 insertion(+), 70 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index 8544ea9..31c861b 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -1507,15 +1507,7 @@ class Assert static::string($value); static::string($pattern); - if (false === $result = @\preg_match($pattern, $value)) { - static::reportInvalidArgument(\sprintf( - 'The pattern %s could not be evaluated: %s.', - static::valueToString($pattern), - \preg_last_error_msg() - )); - } - - if (0 === $result) { + if (!\preg_match($pattern, $value)) { $message = self::resolveMessage($message); static::reportInvalidArgument(\sprintf( $message ?: 'The value %s does not match the expected pattern.', diff --git a/tests/AssertTest.php b/tests/AssertTest.php index 1fc73a6..f0ec064 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -19,7 +19,6 @@ use DateTime; use DateTimeImmutable; use Error; use Exception; -use InvalidArgumentException; use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -992,66 +991,6 @@ class AssertTest extends TestCase Assert::null(DummyEnum::CaseName, 'Expected null. Got: %s'); } - public function testRegexRejectsAnUncompilablePattern(): void - { - $this->expectException('\InvalidArgumentException'); - $this->expectExceptionMessage('The pattern "/(/" could not be evaluated: Internal error.'); - - Assert::regex('abc', '/(/'); - } - - public function testRegexSuppressesTheWarningForAnUncompilablePattern(): void - { - $reported = []; - // PHPUnit masks E_WARNING out of error_reporting(); restore it here. - $errorReporting = error_reporting(E_ALL); - set_error_handler(static function (int $errno, string $message) use (&$reported): bool { - // This is what a well behaved error handler does with a suppressed diagnostic. - if (0 !== (error_reporting() & $errno)) { - $reported[] = $message; - } - - return true; - }); - - try { - Assert::regex('abc', '/(/'); - } catch (InvalidArgumentException) { - // The assertion is expected to fail; this test only inspects the reported errors. - } finally { - restore_error_handler(); - error_reporting($errorReporting); - } - - $this->assertSame([], $reported); - } - - public function testRegexDoesNotUseTheCustomMessageForAnUncompilablePattern(): void - { - $this->expectException('\InvalidArgumentException'); - $this->expectExceptionMessage('The pattern "/(/" could not be evaluated: Internal error.'); - - Assert::regex('abc', '/(/', 'The value %s is not a valid slug.'); - } - - public function testRegexRejectsAPatternExceedingTheBacktrackLimit(): void - { - $backtrackLimit = ini_get('pcre.backtrack_limit'); - ini_set('pcre.backtrack_limit', '100'); - - try { - Assert::regex(str_repeat('a', 30).'c', '/^(a+)+$/'); - $this->fail('Expected an InvalidArgumentException to be thrown.'); - } catch (InvalidArgumentException $e) { - $this->assertSame( - 'The pattern "/^(a+)+$/" could not be evaluated: Backtrack limit exhausted.', - $e->getMessage() - ); - } finally { - ini_set('pcre.backtrack_limit', $backtrackLimit); - } - } - #[DataProvider('getMethodsThatUseOtherMethods')] public function testMessageIsPassedToInternalCalls(string $method, array $args, string $exceptionMessage): void {