Skip to content

Commit e1a0277

Browse files
staabmsebastianbergmann
authored andcommitted
Fix handling of regex containing / in IgnorePhpunitWarnings
1 parent 521c7bf commit e1a0277

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Metadata/IgnorePhpunitWarnings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public function isIgnorePhpunitWarnings(): true
4040
public function shouldIgnore(string $message): bool
4141
{
4242
return $this->messagePattern === null ||
43-
(bool) preg_match("/{$this->messagePattern}/", $message);
43+
(bool) preg_match('{' . $this->messagePattern . '}', $message);
4444
}
4545
}

tests/end-to-end/event/_files/PhpunitWarningIgnoredTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ public function testPhpunitWarningWithRegex(): void
5454
$this->assertTrue(true);
5555
}
5656

57+
#[IgnorePhpunitWarnings('warning/error(.*)')]
58+
public function testPhpunitWarningWithSlashInRegex(): void
59+
{
60+
EventFacade::emitter()->testTriggeredPhpunitWarning(
61+
$this->valueObjectForEvents(),
62+
'warning/error message',
63+
);
64+
65+
$this->assertTrue(true);
66+
}
67+
5768
#[IgnorePhpunitWarnings('warn(.*)mess(.*)')]
5869
public function testPhpunitWarningWithWrongPattern(): void
5970
{

tests/end-to-end/event/phpunit-warning-ignored.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PHPUnit %s by Sebastian Bergmann and contributors.
1414

1515
Runtime: %s
1616

17-
...W. 5 / 5 (100%)
17+
....W. 6 / 6 (100%)
1818

1919
Time: %s, Memory: %s
2020

@@ -26,4 +26,4 @@ another message
2626
%sPhpunitWarningIgnoredTest.php:%d
2727

2828
OK, but there were issues!
29-
Tests: 5, Assertions: 5, PHPUnit Warnings: 1.
29+
Tests: 6, Assertions: 6, PHPUnit Warnings: 1.

0 commit comments

Comments
 (0)