Skip to content

Commit 8f9938a

Browse files
committed
added Assert::notMatch()
1 parent 4b8a851 commit 8f9938a

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/Framework/Assert.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,19 @@ public static function match(string $pattern, string $actual, ?string $descripti
449449
}
450450

451451

452+
public static function notMatch(string $pattern, string $actual, ?string $description = null): void
453+
{
454+
self::$counter++;
455+
if (self::isMatching($pattern, $actual)) {
456+
if (self::$expandPatterns) {
457+
[$pattern, $actual] = self::expandMatchingPatterns($pattern, $actual);
458+
}
459+
460+
self::fail(self::describe('%1 should not match %2', $description), $actual, $pattern);
461+
}
462+
}
463+
464+
452465
/**
453466
* Asserts that a string matches a given pattern stored in file.
454467
*/

tests/Framework/Assert.match.phpt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,7 @@ foreach ($matches as [$expected, $actual]) {
8787
}
8888

8989
foreach ($notMatches as [$expected, $actual, $expected2, $actual2]) {
90-
$expected3 = str_replace('%', '%%', $expected2);
91-
$actual3 = str_replace('%', '%%', $actual2);
92-
93-
$ex = Assert::exception(
94-
fn() => Assert::match($expected, $actual),
95-
Tester\AssertException::class,
96-
Dumper::toLine($actual3) . ' should match ' . Dumper::toLine($expected3),
97-
);
98-
99-
Assert::same($expected2, $ex->expected);
100-
Assert::same($actual2, $ex->actual);
90+
Assert::notMatch($expected, $actual);
10191
}
10292

10393

0 commit comments

Comments
 (0)