|
7 | 7 | use Codeception\PHPUnit\TestCase;
|
8 | 8 | use PHPUnit\Framework\Assert;
|
9 | 9 | use PHPUnit\Framework\Constraint\Constraint as PHPUnitConstraint;
|
| 10 | +use PHPUnit\Framework\Constraint\LogicalNot; |
| 11 | +use PHPUnit\Framework\Constraint\StringMatchesFormatDescription; |
10 | 12 |
|
11 | 13 | trait InheritedAsserts
|
12 | 14 | {
|
@@ -1082,15 +1084,37 @@ protected function assertStringNotEqualsFileIgnoringCase(string $expectedFile, s
|
1082 | 1084 | */
|
1083 | 1085 | protected function assertStringNotMatchesFormat(string $format, string $string, string $message = '')
|
1084 | 1086 | {
|
1085 |
| - Assert::assertStringNotMatchesFormat($format, $string, $message); |
| 1087 | + trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 12', E_USER_DEPRECATED); |
| 1088 | + |
| 1089 | + if (method_exists(Assert::class, 'assertStringNotMatchesFormat')) { |
| 1090 | + Assert::assertStringNotMatchesFormat($format, $string, $message); |
| 1091 | + } else { |
| 1092 | + $constraint = new LogicalNot(new StringMatchesFormatDescription($format)); |
| 1093 | + |
| 1094 | + Assert::assertThat($string, $constraint, $message); |
| 1095 | + } |
1086 | 1096 | }
|
1087 | 1097 |
|
1088 | 1098 | /**
|
1089 | 1099 | * Asserts that a string does not match a given format string.
|
1090 | 1100 | */
|
1091 | 1101 | protected function assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = '')
|
1092 | 1102 | {
|
1093 |
| - Assert::assertStringNotMatchesFormatFile($formatFile, $string, $message); |
| 1103 | + trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 12', E_USER_DEPRECATED); |
| 1104 | + |
| 1105 | + if (method_exists(Assert::class, 'assertStringNotMatchesFormatFile')) { |
| 1106 | + Assert::assertStringNotMatchesFormatFile($formatFile, $string, $message); |
| 1107 | + } else { |
| 1108 | + Assert::assertFileExists($formatFile); |
| 1109 | + |
| 1110 | + $constraint = new LogicalNot( |
| 1111 | + new StringMatchesFormatDescription( |
| 1112 | + file_get_contents($formatFile) |
| 1113 | + ) |
| 1114 | + ); |
| 1115 | + |
| 1116 | + Assert::assertThat($string, $constraint, $message); |
| 1117 | + } |
1094 | 1118 | }
|
1095 | 1119 |
|
1096 | 1120 | /**
|
|
0 commit comments