diff --git a/library/Icinga/Test/BaseTestCase.php b/library/Icinga/Test/BaseTestCase.php index a293f7b6f..aea79210f 100644 --- a/library/Icinga/Test/BaseTestCase.php +++ b/library/Icinga/Test/BaseTestCase.php @@ -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(); diff --git a/modules/monitoring/test/php/application/views/helpers/PluginOutputTest.php b/modules/monitoring/test/php/application/views/helpers/PluginOutputTest.php index 76e67c6ff..94efee939 100644 --- a/modules/monitoring/test/php/application/views/helpers/PluginOutputTest.php +++ b/modules/monitoring/test/php/application/views/helpers/PluginOutputTest.php @@ -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'); diff --git a/test/php/library/Icinga/File/Ini/IniWriterTest.php b/test/php/library/Icinga/File/Ini/IniWriterTest.php index d70aa2e8f..41e1f13e6 100644 --- a/test/php/library/Icinga/File/Ini/IniWriterTest.php +++ b/test/php/library/Icinga/File/Ini/IniWriterTest.php @@ -275,7 +275,7 @@ inkey' => 'blarg' ); $rendered = $writer->render(); - $this->assertRegExp( + $this->assertMatchesRegularExpression( '~linebreak\\\\nin line~', $rendered, 'newlines in values are not escaped'