From 5f0ca7243aa892df1cc48eaa72a33875495d2637 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Mon, 6 Oct 2025 22:08:56 +0200 Subject: [PATCH] fix: test IgnorePhpunitWarnings pattern in Emitter --- src/Event/Emitter/DispatchingEmitter.php | 4 +- src/Metadata/IgnorePhpunitWarnings.php | 8 ++-- .../Metadata/IgnorePhpunitWarningsTest.php | 39 ------------------- 3 files changed, 8 insertions(+), 43 deletions(-) delete mode 100644 tests/unit/Metadata/IgnorePhpunitWarningsTest.php diff --git a/src/Event/Emitter/DispatchingEmitter.php b/src/Event/Emitter/DispatchingEmitter.php index 606eac4dd9..6abe264048 100644 --- a/src/Event/Emitter/DispatchingEmitter.php +++ b/src/Event/Emitter/DispatchingEmitter.php @@ -1020,7 +1020,9 @@ public function testTriggeredPhpunitWarning(Code\Test $test, string $message): v if (isset($metadata[0])) { assert($metadata[0] instanceof IgnorePhpunitWarnings); - if ($metadata[0]->shouldIgnore($message)) { + $messagePattern = $metadata[0]->messagePattern(); + + if ($messagePattern === null || (bool) preg_match('{' . $messagePattern . '}', $message)) { $ignoredByTest = true; } } diff --git a/src/Metadata/IgnorePhpunitWarnings.php b/src/Metadata/IgnorePhpunitWarnings.php index bf50c98e71..6e5a026ebb 100644 --- a/src/Metadata/IgnorePhpunitWarnings.php +++ b/src/Metadata/IgnorePhpunitWarnings.php @@ -37,9 +37,11 @@ public function isIgnorePhpunitWarnings(): true return true; } - public function shouldIgnore(string $message): bool + /** + * @return null|non-empty-string + */ + public function messagePattern(): ?string { - return $this->messagePattern === null || - (bool) preg_match('{' . $this->messagePattern . '}', $message); + return $this->messagePattern; } } diff --git a/tests/unit/Metadata/IgnorePhpunitWarningsTest.php b/tests/unit/Metadata/IgnorePhpunitWarningsTest.php deleted file mode 100644 index e4b1f9a4fc..0000000000 --- a/tests/unit/Metadata/IgnorePhpunitWarningsTest.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace PHPUnit\Metadata; - -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Small; -use PHPUnit\Framework\TestCase; - -#[CoversClass(IgnorePhpunitWarnings::class)] -#[Small] -final class IgnorePhpunitWarningsTest extends TestCase -{ - public static function shouldIgnoreProvider(): array - { - return [ - 'null pattern ignores any message' => [null, 'any warning message', true], - 'pattern matches message' => ['warning.*message', 'warning test message', true], - 'pattern does not match different message' => ['warning.*message', 'different message', false], - 'exact match works' => ['exact warning message', 'exact warning message', true], - 'exact match does not match different' => ['exact warning message', 'different warning message', false], - ]; - } - - #[DataProvider('shouldIgnoreProvider')] - public function testShouldIgnore(?string $messagePattern, string $message, bool $expected): void - { - $metadata = Metadata::ignorePhpunitWarnings($messagePattern); - - $this->assertSame($expected, $metadata->shouldIgnore($message)); - } -}