From d1a48ad34cae8570e606a467c7957dac6a501021 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 8 Sep 2022 12:16:36 +1000 Subject: [PATCH] Use mysql version from server rather than mysql --version mysql --version is the version of the client program and not necessarly the server version. Get the version accurate for the reports generated. --- functions.php | 9 ++++++++- prepare.php | 10 +++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/functions.php b/functions.php index b092569..17cfdf9 100644 --- a/functions.php +++ b/functions.php @@ -184,11 +184,14 @@ function upload_results( $results, $rev, $message, $env, $api_key ) { * Get the environmental details */ function get_env_details() { + $WPT_DB_HOST = getenv( 'WPT_DB_HOST' ) ? : 'localhost'; + $WPT_DB_USER = getenv( 'WPT_DB_USER' ); + $WPT_DB_PASSWORD = getenv( 'WPT_DB_PASSWORD' ); + $WPT_DB_NAME = getenv( 'WPT_DB_NAME' ); $env = array( 'php_version' => phpversion(), 'php_modules' => array(), 'system_utils' => array(), - 'mysql_version' => trim( shell_exec( 'mysql --version' ) ), 'os_name' => trim( shell_exec( 'uname -s' ) ), 'os_version' => trim( shell_exec( 'uname -r' ) ), ); @@ -214,6 +217,10 @@ function get_env_details() { $curl_bits = explode( PHP_EOL, str_replace( 'curl ', '', shell_exec( 'curl --version' ) ) ); $curl = array_shift( $curl_bits ); $env['system_utils']['curl'] = trim( $curl ); + $mysqli = new mysqli($WPT_DB_HOST, $WPT_DB_USER, $WPT_DB_PASSWORD, $WPT_DB_NAME); + $env['mysql_version'] = $mysqli->query("SELECT VERSION()")->fetch_row()[0]; + $mysqli->close(); + if ( class_exists( 'Imagick' ) ) { $imagick = new Imagick(); $version = $imagick->getVersion(); diff --git a/prepare.php b/prepare.php index 04b891b..f93158e 100644 --- a/prepare.php +++ b/prepare.php @@ -54,7 +54,6 @@ 'php_version' => phpversion(), 'php_modules' => array(), 'system_utils' => array(), - 'mysql_version' => trim( shell_exec( 'mysql --version' ) ), 'os_name' => trim( shell_exec( 'uname -s' ) ), 'os_version' => trim( shell_exec( 'uname -r' ) ), ); @@ -92,13 +91,18 @@ \$env['system_utils']['graphicsmagick'] = \$version[1]; } \$env['system_utils']['openssl'] = str_replace( 'OpenSSL ', '', trim( shell_exec( 'openssl version' ) ) ); +EOT; +$db_version = <<query("SELECT VERSION()")->fetch_row()[0]; +\$mysqli->close(); file_put_contents( __DIR__ . '/tests/phpunit/build/logs/env.json', json_encode( \$env, JSON_PRETTY_PRINT ) ); if ( 'cli' === php_sapi_name() && defined( 'WP_INSTALLING' ) && WP_INSTALLING ) { echo PHP_EOL; echo 'PHP version: ' . phpversion() . ' (' . realpath( \$_SERVER['_'] ) . ')' . PHP_EOL; echo PHP_EOL; } -EOT; +EODB; $logger_replace_string = '// ** Database settings ** //' . PHP_EOL; $system_logger = $logger_replace_string . $system_logger; $php_binary_string = 'define( \'WP_PHP_BINARY\', \''. $WPT_PHP_EXECUTABLE . '\' );'; @@ -112,7 +116,7 @@ $logger_replace_string => $system_logger, ); $contents = str_replace( array_keys( $search_replace ), array_values( $search_replace ), $contents ); -file_put_contents( $WPT_PREPARE_DIR . '/wp-tests-config.php', $contents ); +file_put_contents( $WPT_PREPARE_DIR . '/wp-tests-config.php', $contents . $db_version); // Now, install PHPUnit based on the test environment's PHP Version $php_version_cmd = $WPT_PHP_EXECUTABLE . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;\"";