From 1df32b32e0dd9168b2fa2b883bd6037edeb7fd27 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 9 Sep 2023 17:28:39 +0200 Subject: [PATCH] Backport two test methods for phpunit 8.5 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Krög --- test/classes/AbstractTestCase.php | 27 ++++++++++++++++++++++++++ test/classes/Config/FormTest.php | 17 ++-------------- test/classes/Gis/GisGeometryCollectionTest.php | 17 ++++------------ test/classes/RoutingTest.php | 9 +-------- test/classes/UrlTest.php | 15 ++------------ 5 files changed, 36 insertions(+), 49 deletions(-) diff --git a/test/classes/AbstractTestCase.php b/test/classes/AbstractTestCase.php index 45fdc9850a..d20e8b0eeb 100644 --- a/test/classes/AbstractTestCase.php +++ b/test/classes/AbstractTestCase.php @@ -20,6 +20,7 @@ use ReflectionClass; use function array_keys; use function in_array; +use function method_exists; use const DIRECTORY_SEPARATOR; @@ -120,6 +121,32 @@ abstract class AbstractTestCase extends TestCase $this->fail('Some error codes where not used !'); } + /** + * PHPUnit 8 compatibility + */ + public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void + { + if (method_exists(TestCase::class, 'assertMatchesRegularExpression')) { + parent::assertMatchesRegularExpression($pattern, $string, $message); + } else { + /** @psalm-suppress DeprecatedMethod */ + self::assertRegExp($pattern, $string, $message); + } + } + + /** + * PHPUnit 8 compatibility + */ + public static function assertFileDoesNotExist(string $filename, string $message = ''): void + { + if (method_exists(TestCase::class, 'assertFileDoesNotExist')) { + parent::assertFileDoesNotExist($filename, $message); + } else { + /** @psalm-suppress DeprecatedMethod */ + parent::assertFileNotExists($filename, $message); + } + } + protected function loadContainerBuilder(): void { global $containerBuilder; diff --git a/test/classes/Config/FormTest.php b/test/classes/Config/FormTest.php index f0fc316ec9..c7647d2c8d 100644 --- a/test/classes/Config/FormTest.php +++ b/test/classes/Config/FormTest.php @@ -11,7 +11,6 @@ use ReflectionClass; use ReflectionProperty; use function array_keys; -use function method_exists; use function preg_match; /** @@ -151,13 +150,7 @@ class FormTest extends AbstractTestCase $this->assertIsString($result[1]); // needs regexp because the counter is static - - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression('/^preffoo\/foo\/bar\/\:group\:end\:\d+$/', $result[1]); - } else { - /** @psalm-suppress DeprecatedMethod */ - $this->assertRegExp('/^preffoo\/foo\/bar\/\:group\:end\:\d+$/', $result[1]); - } + $this->assertMatchesRegularExpression('/^preffoo\/foo\/bar\/\:group\:end\:\d+$/', $result[1]); } /** @@ -193,13 +186,7 @@ class FormTest extends AbstractTestCase $keys = array_keys($result); $key = $keys[0]; $this->assertIsString($key); - - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression('/^\:group\:end\:(\d+)$/', $key); - } else { - /** @psalm-suppress DeprecatedMethod */ - $this->assertRegExp('/^\:group\:end\:(\d+)$/', $key); - } + $this->assertMatchesRegularExpression('/^\:group\:end\:(\d+)$/', $key); preg_match('/^\:group\:end\:(\d+)$/', $key, $matches); $digit = $matches[1]; diff --git a/test/classes/Gis/GisGeometryCollectionTest.php b/test/classes/Gis/GisGeometryCollectionTest.php index aa4ae50d2c..6df045ef21 100644 --- a/test/classes/Gis/GisGeometryCollectionTest.php +++ b/test/classes/Gis/GisGeometryCollectionTest.php @@ -9,7 +9,6 @@ use PhpMyAdmin\Image\ImageWrapper; use PhpMyAdmin\Tests\AbstractTestCase; use TCPDF; -use function method_exists; use function preg_match; /** @@ -320,18 +319,10 @@ class GisGeometryCollectionTest extends AbstractTestCase $string = $this->object->prepareRowAsSvg($spatial, $label, $lineColor, $scaleData); $this->assertEquals(1, preg_match($output, $string)); - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression( - $output, - $this->object->prepareRowAsSvg($spatial, $label, $lineColor, $scaleData) - ); - } else { - /** @psalm-suppress DeprecatedMethod */ - $this->assertRegExp( - $output, - $this->object->prepareRowAsSvg($spatial, $label, $lineColor, $scaleData) - ); - } + $this->assertMatchesRegularExpression( + $output, + $this->object->prepareRowAsSvg($spatial, $label, $lineColor, $scaleData) + ); } /** diff --git a/test/classes/RoutingTest.php b/test/classes/RoutingTest.php index 19b81dd537..6ba90bb659 100644 --- a/test/classes/RoutingTest.php +++ b/test/classes/RoutingTest.php @@ -9,7 +9,6 @@ use PhpMyAdmin\Controllers\HomeController; use PhpMyAdmin\Routing; use function copy; -use function method_exists; use function unlink; use const CACHE_DIR; @@ -49,13 +48,7 @@ class RoutingTest extends AbstractTestCase // Create new cache file. $this->assertTrue(unlink($cacheFilename)); - - if (method_exists($this, 'assertFileDoesNotExist')) { - $this->assertFileDoesNotExist($cacheFilename); - } else { - /** @psalm-suppress DeprecatedMethod */ - $this->assertFileNotExists($cacheFilename); - } + $this->assertFileDoesNotExist($cacheFilename); $dispatcher = Routing::getDispatcher(); $this->assertInstanceOf(Dispatcher::class, $dispatcher); diff --git a/test/classes/UrlTest.php b/test/classes/UrlTest.php index 0e54fe1fbe..56749105f6 100644 --- a/test/classes/UrlTest.php +++ b/test/classes/UrlTest.php @@ -7,7 +7,6 @@ namespace PhpMyAdmin\Tests; use PhpMyAdmin\Url; use function is_string; -use function method_exists; use function parse_str; use function str_repeat; use function urldecode; @@ -214,12 +213,7 @@ class UrlTest extends AbstractTestCase $this->assertSame('0', $queryParams['pos']); $this->assertTrue(is_string($queryParams['eq'])); $this->assertNotSame('', $queryParams['eq']); - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression('/^[a-zA-Z0-9-_=]+$/', $queryParams['eq']); - } else { - /** @psalm-suppress DeprecatedMethod */ - $this->assertRegExp('/^[a-zA-Z0-9-_=]+$/', $queryParams['eq']); - } + $this->assertMatchesRegularExpression('/^[a-zA-Z0-9-_=]+$/', $queryParams['eq']); $decrypted = Url::decryptQuery($queryParams['eq']); $this->assertNotNull($decrypted); @@ -242,12 +236,7 @@ class UrlTest extends AbstractTestCase $encrypted = Url::encryptQuery($query); $this->assertNotSame($query, $encrypted); $this->assertNotSame('', $encrypted); - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression('/^[a-zA-Z0-9-_=]+$/', $encrypted); - } else { - /** @psalm-suppress DeprecatedMethod */ - $this->assertRegExp('/^[a-zA-Z0-9-_=]+$/', $encrypted); - } + $this->assertMatchesRegularExpression('/^[a-zA-Z0-9-_=]+$/', $encrypted); $decrypted = Url::decryptQuery($encrypted); $this->assertSame($query, $decrypted); -- 2.11.4.GIT