Skip to content

Commit

Permalink
Use expectExceptionMessageMatches() instead of deprecated expectExcep…
Browse files Browse the repository at this point in the history
…tionMessageRegExp()
  • Loading branch information
sebastianbergmann committed Mar 30, 2020
1 parent 8d399fd commit 7d2ffc8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public function expectDeprecationMessage(string $message): void

public function expectDeprecationMessageMatches(string $regularExpression): void
{
$this->expectExceptionMessageRegExp($regularExpression);
$this->expectExceptionMessageMatches($regularExpression);
}

public function expectNotice(): void
Expand All @@ -553,7 +553,7 @@ public function expectNoticeMessage(string $message): void

public function expectNoticeMessageMatches(string $regularExpression): void
{
$this->expectExceptionMessageRegExp($regularExpression);
$this->expectExceptionMessageMatches($regularExpression);
}

public function expectWarning(): void
Expand All @@ -568,7 +568,7 @@ public function expectWarningMessage(string $message): void

public function expectWarningMessageMatches(string $regularExpression): void
{
$this->expectExceptionMessageRegExp($regularExpression);
$this->expectExceptionMessageMatches($regularExpression);
}

public function expectError(): void
Expand All @@ -583,7 +583,7 @@ public function expectErrorMessage(string $message): void

public function expectErrorMessageMatches(string $regularExpression): void
{
$this->expectExceptionMessageRegExp($regularExpression);
$this->expectExceptionMessageMatches($regularExpression);
}

public function getStatus(): int
Expand Down Expand Up @@ -1925,7 +1925,7 @@ private function setExpectedExceptionFromAnnotation(): void
if ($expectedException['message'] !== '') {
$this->expectExceptionMessage($expectedException['message']);
} elseif ($expectedException['message_regex'] !== '') {
$this->expectExceptionMessageRegExp($expectedException['message_regex']);
$this->expectExceptionMessageMatches($expectedException['message_regex']);
}
}
} catch (UtilException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ final class ExceptionMessageRegExpTest extends TestCase
public function testRegexMessage(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/^A polymorphic \w+ message/');
$this->expectExceptionMessageMatches('/^A polymorphic \w+ message/');

throw new \Exception('A polymorphic exception message');
}

public function testRegexMessageExtreme(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/^a poly[a-z]+ [a-zA-Z0-9_]+ me(s){2}age$/i');
$this->expectExceptionMessageMatches('/^a poly[a-z]+ [a-zA-Z0-9_]+ me(s){2}age$/i');

throw new \Exception('A polymorphic exception message');
}
Expand All @@ -41,7 +41,7 @@ public function testMessageXdebugScreamCompatibility(): void
\ini_set('xdebug.scream', '1');

$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('#Screaming preg_match#');
$this->expectExceptionMessageMatches('#Screaming preg_match#');

throw new \Exception('Screaming preg_match');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Framework/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function testExceptionWithRegexpMessage(): void
{
$test = new \ThrowExceptionTestCase('test');
$test->expectException(\RuntimeException::class);
$test->expectExceptionMessageRegExp('/runtime .*? occurred/');
$test->expectExceptionMessageMatches('/runtime .*? occurred/');

$result = $test->run();

Expand All @@ -347,7 +347,7 @@ public function testExpectExceptionMessageRegExpAllowsAccessingExpectedException

$test = new \ThrowExceptionTestCase('test');

$test->expectExceptionMessageRegExp($messageRegExp);
$test->expectExceptionMessageMatches($messageRegExp);

$this->assertSame($messageRegExp, $test->getExpectedExceptionMessageRegExp());
}
Expand All @@ -356,7 +356,7 @@ public function testExceptionWithWrongRegexpMessage(): void
{
$test = new \ThrowExceptionTestCase('test');
$test->expectException(\RuntimeException::class);
$test->expectExceptionMessageRegExp('/logic .*? occurred/');
$test->expectExceptionMessageMatches('/logic .*? occurred/');

$result = $test->run();

Expand All @@ -372,7 +372,7 @@ public function testExceptionWithInvalidRegexpMessage(): void
{
$test = new \ThrowExceptionTestCase('test');
$test->expectException(\RuntimeException::class);
$test->expectExceptionMessageRegExp('#runtime .*? occurred/');
$test->expectExceptionMessageMatches('#runtime .*? occurred/');

$test->run();

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Util/TestClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed(): void
), VariousDocblockDefinedDataProvider::class);

$this->expectException(Exception::class);
$this->expectExceptionMessageRegExp('/^The data set for the @testWith annotation cannot be parsed:/');
$this->expectExceptionMessageMatches('/^The data set for the @testWith annotation cannot be parsed:/');

$docBlock->getProvidedData();
}
Expand All @@ -1098,7 +1098,7 @@ public function testTestWithThrowsProperExceptionIfMultiLineDatasetCannotBeParse
), VariousDocblockDefinedDataProvider::class);

$this->expectException(Exception::class);
$this->expectExceptionMessageRegExp('/^The data set for the @testWith annotation cannot be parsed:/');
$this->expectExceptionMessageMatches('/^The data set for the @testWith annotation cannot be parsed:/');

$docBlock->getProvidedData();
}
Expand Down

0 comments on commit 7d2ffc8

Please sign in to comment.