Skip to content

Commit b8ac5d7

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

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare(strict_types=1);
44

55
use Tester\Assert;
6-
use Tester\Dumper;
76

87
require __DIR__ . '/../bootstrap.php';
98

@@ -87,17 +86,7 @@ foreach ($matches as [$expected, $actual]) {
8786
}
8887

8988
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);
89+
Assert::notMatch($expected, $actual);
10190
}
10291

10392

0 commit comments

Comments
 (0)