From c50faeafee31edba9fff5819da8fdd7d7028aee0 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Mon, 6 Apr 2020 00:25:00 +0300 Subject: [PATCH] Allow PHPUnit 9 (#3072) * Allow PHPUnit 9 Had to add a couple of compatibility shims to keep tests the same. * import method_exists() --- composer.json | 2 +- tests/TestCase.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e4346aa11..8df9810de 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "brianium/paratest": "^4.0.0", "phpmyadmin/sql-parser": "5.1.0", "phpspec/prophecy": ">=1.9.0", - "phpunit/phpunit": "^7.5.16 || ^8.5", + "phpunit/phpunit": "^7.5.16 || ^8.5 || ^9.0", "psalm/plugin-phpunit": "^0.9", "slevomat/coding-standard": "^5.0", "squizlabs/php_codesniffer": "^3.5", diff --git a/tests/TestCase.php b/tests/TestCase.php index 251a6bc2c..3500884a6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,7 @@ use function defined; use const DIRECTORY_SEPARATOR; use function getcwd; use function ini_set; +use function method_exists; use PHPUnit\Framework\TestCase as BaseTestCase; use Psalm\Config; use Psalm\Internal\Analyzer\FileAnalyzer; @@ -153,4 +154,26 @@ class TestCase extends BaseTestCase return $name; } + + /** + * Compatibility alias + */ + public function expectExceptionMessageRegExp(string $regexp): void + { + if (method_exists($this, 'expectExceptionMessageMatches')) { + $this->expectExceptionMessageMatches($regexp); + } else { + /** @psalm-suppress UndefinedMethod */ + parent::expectExceptionMessageRegExp($regexp); + } + } + + public static function assertRegExp(string $pattern, string $string, string $message = ''): void + { + if (method_exists(self::class, 'assertMatchesRegularExpression')) { + self::assertMatchesRegularExpression($pattern, $string, $message); + } else { + parent::assertRegExp($pattern, $string, $message); + } + } }