From 3e740230c32e4b2110f3eb4dc155616cb24aaca2 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 22 Aug 2022 16:40:54 +0000 Subject: [PATCH] Tests: Correct MariaDB version check in database charset tests. MariaDB version is reported differently between PHP versions: * PHP 8.0.16 or later: `10.6.8-MariaDB` * PHP 8.0.15 or earlier: `5.5.5-10.6.8-MariaDB` The latter includes PHP 7.4.x and PHP 5.6.x as well, where the version is also reported with the `5.5.5-` prefix. This commit makes an adjustment to the `Tests_DB_Charset` class to check for the correct version. References: * [https://github.com/php/php-src/issues/7972 php-src: #7972: MariaDB version prefix 5.5.5- is not stripped] * [https://github.com/php/php-src/pull/7963 php-src: PR #7963 Fix GH-7932: MariaDB version prefix not always stripped] Follow-up to [53918]. Fixes #53623. git-svn-id: https://develop.svn.wordpress.org/trunk@53919 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/db/charset.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/phpunit/tests/db/charset.php b/tests/phpunit/tests/db/charset.php index 35135c8e7c..6fc2162526 100644 --- a/tests/phpunit/tests/db/charset.php +++ b/tests/phpunit/tests/db/charset.php @@ -46,6 +46,15 @@ class Tests_DB_Charset extends WP_UnitTestCase { self::$db_version = self::$_wpdb->db_version(); self::$db_server_info = self::$_wpdb->db_server_info(); + // Account for MariaDB version being prefixed with '5.5.5-' on older PHP versions. + if ( str_contains( self::$db_server_info, 'MariaDB' ) && '5.5.5' === self::$db_version + && PHP_VERSION_ID < 80016 // PHP 8.0.15 or older. + ) { + // Strip the '5.5.5-' prefix and set the version to the correct value. + self::$db_server_info = preg_replace( '/^5\.5\.5-(.*)/', '$1', self::$db_server_info ); + self::$db_version = preg_replace( '/[^0-9.].*/', '', self::$db_server_info ); + } + /* * MariaDB 10.6.1 or later and MySQL 8.0.30 or later * use utf8mb3 instead of utf8 in various commands output.