Skip to content

Commit d1a48ad

Browse files
committed
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.
1 parent 1c32d0c commit d1a48ad

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

functions.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,14 @@ function upload_results( $results, $rev, $message, $env, $api_key ) {
184184
* Get the environmental details
185185
*/
186186
function get_env_details() {
187+
$WPT_DB_HOST = getenv( 'WPT_DB_HOST' ) ? : 'localhost';
188+
$WPT_DB_USER = getenv( 'WPT_DB_USER' );
189+
$WPT_DB_PASSWORD = getenv( 'WPT_DB_PASSWORD' );
190+
$WPT_DB_NAME = getenv( 'WPT_DB_NAME' );
187191
$env = array(
188192
'php_version' => phpversion(),
189193
'php_modules' => array(),
190194
'system_utils' => array(),
191-
'mysql_version' => trim( shell_exec( 'mysql --version' ) ),
192195
'os_name' => trim( shell_exec( 'uname -s' ) ),
193196
'os_version' => trim( shell_exec( 'uname -r' ) ),
194197
);
@@ -214,6 +217,10 @@ function get_env_details() {
214217
$curl_bits = explode( PHP_EOL, str_replace( 'curl ', '', shell_exec( 'curl --version' ) ) );
215218
$curl = array_shift( $curl_bits );
216219
$env['system_utils']['curl'] = trim( $curl );
220+
$mysqli = new mysqli($WPT_DB_HOST, $WPT_DB_USER, $WPT_DB_PASSWORD, $WPT_DB_NAME);
221+
$env['mysql_version'] = $mysqli->query("SELECT VERSION()")->fetch_row()[0];
222+
$mysqli->close();
223+
217224
if ( class_exists( 'Imagick' ) ) {
218225
$imagick = new Imagick();
219226
$version = $imagick->getVersion();

prepare.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
'php_version' => phpversion(),
5555
'php_modules' => array(),
5656
'system_utils' => array(),
57-
'mysql_version' => trim( shell_exec( 'mysql --version' ) ),
5857
'os_name' => trim( shell_exec( 'uname -s' ) ),
5958
'os_version' => trim( shell_exec( 'uname -r' ) ),
6059
);
@@ -92,13 +91,18 @@
9291
\$env['system_utils']['graphicsmagick'] = \$version[1];
9392
}
9493
\$env['system_utils']['openssl'] = str_replace( 'OpenSSL ', '', trim( shell_exec( 'openssl version' ) ) );
94+
EOT;
95+
$db_version = <<<EODB
96+
\$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
97+
\$env['mysql_version'] = \$mysqli->query("SELECT VERSION()")->fetch_row()[0];
98+
\$mysqli->close();
9599
file_put_contents( __DIR__ . '/tests/phpunit/build/logs/env.json', json_encode( \$env, JSON_PRETTY_PRINT ) );
96100
if ( 'cli' === php_sapi_name() && defined( 'WP_INSTALLING' ) && WP_INSTALLING ) {
97101
echo PHP_EOL;
98102
echo 'PHP version: ' . phpversion() . ' (' . realpath( \$_SERVER['_'] ) . ')' . PHP_EOL;
99103
echo PHP_EOL;
100104
}
101-
EOT;
105+
EODB;
102106
$logger_replace_string = '// ** Database settings ** //' . PHP_EOL;
103107
$system_logger = $logger_replace_string . $system_logger;
104108
$php_binary_string = 'define( \'WP_PHP_BINARY\', \''. $WPT_PHP_EXECUTABLE . '\' );';
@@ -112,7 +116,7 @@
112116
$logger_replace_string => $system_logger,
113117
);
114118
$contents = str_replace( array_keys( $search_replace ), array_values( $search_replace ), $contents );
115-
file_put_contents( $WPT_PREPARE_DIR . '/wp-tests-config.php', $contents );
119+
file_put_contents( $WPT_PREPARE_DIR . '/wp-tests-config.php', $contents . $db_version);
116120

117121
// Now, install PHPUnit based on the test environment's PHP Version
118122
$php_version_cmd = $WPT_PHP_EXECUTABLE . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;\"";

0 commit comments

Comments
 (0)