tests: Don't use deprecated assertion `assertRegExp()`

This commit is contained in:
Johannes Meyer 2021-04-09 11:07:46 +02:00
parent f27e872d90
commit e671324ddb
3 changed files with 19 additions and 2 deletions

View File

@ -333,6 +333,23 @@ namespace Icinga\Test {
$adapter->exec('DROP TABLE ' . $table . ';');
}
}
/**
* Add assertMatchesRegularExpression() method for phpunit >= 8.0 < 9.0 for compatibility with PHP 7.2.
*
* @TODO Remove once PHP 7.2 support is not needed for testing anymore.
*/
public static function assertMatchesRegularExpression(
string $pattern,
string $string,
string $message = ''
): void {
if (method_exists(parent::class, 'assertMatchesRegularExpression')) {
parent::assertMatchesRegularExpression($pattern, $string, $message);
} else {
static::assertRegExp($pattern, $string, $message);
}
}
}
BaseTestCase::setupTimezone();

View File

@ -45,7 +45,7 @@ class PluginOutputTest extends BaseTestCase
$html,
preg_quote(self::SUFFIX, '~')
);
$this->assertRegExp($expect, $actual, 'Output must match example regexp');
$this->assertMatchesRegularExpression($expect, $actual, 'Output must match example regexp');
} else {
$expect = $prefix . $html . self::SUFFIX;
$this->assertEquals($expect, $actual, 'Output must match example');

View File

@ -275,7 +275,7 @@ inkey' => 'blarg'
);
$rendered = $writer->render();
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'~linebreak\\\\nin line~',
$rendered,
'newlines in values are not escaped'