Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,8 @@ public function __construct() {
if ( getenv( 'WP_CLI_TEST_DBTYPE' ) ) {
$this->variables['DB_TYPE'] = getenv( 'WP_CLI_TEST_DBTYPE' );
} else {
$this->variables['DB_TYPE'] = 'mysql';
// Auto-detect database type if not explicitly set
$this->variables['DB_TYPE'] = Utils\get_db_type();
Comment on lines +837 to +838
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code calls Utils\get_db_type() from the WP_CLI\Utils namespace, but it's unclear if this function exists in the wp-cli package (specified as version ^2.12 in composer.json). If this function doesn't exist yet, this change will cause a fatal error when the constructor runs. Please verify that:

  1. The function exists in wp-cli v2.12 or later, OR
  2. A minimum version requirement that includes this function should be added to composer.json, OR
  3. An alternative implementation should be used (e.g., using the local get_db_type_and_version() function from utils/behat-tags.php)
Suggested change
// Auto-detect database type if not explicitly set
$this->variables['DB_TYPE'] = Utils\get_db_type();
// Auto-detect database type if not explicitly set, if helper is available.
if ( function_exists( '\WP_CLI\Utils\get_db_type' ) ) {
$this->variables['DB_TYPE'] = Utils\get_db_type();
} else {
// Fallback to a sensible default to avoid fatal errors if helper is missing.
$this->variables['DB_TYPE'] = 'mysql';
}

Copilot uses AI. Check for mistakes.
}

if ( getenv( 'MYSQL_TCP_PORT' ) ) {
Expand Down Expand Up @@ -1202,8 +1203,9 @@ public function create_db(): void {
return;
}

$dbname = self::$db_settings['dbname'];
self::run_sql( self::$mysql_binary . ' --no-defaults', [ 'execute' => "CREATE DATABASE IF NOT EXISTS $dbname" ] );
$dbname = self::$db_settings['dbname'];
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description mentions creating a helper method is_mariadb() but the actual implementation uses inline checks 'mariadb' === self::$db_type instead. While the inline approach works, there's a discrepancy between the description and the implementation. Consider either updating the PR description to reflect the actual implementation or extracting the check into the mentioned helper method for better code maintainability and reusability.

Copilot uses AI. Check for mistakes.
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "CREATE DATABASE IF NOT EXISTS $dbname" ] );
}

/**
Expand All @@ -1214,8 +1216,9 @@ public function test_connection(): void {
return;
}

$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
$sql_result = self::run_sql(
self::$mysql_binary . ' --no-defaults',
self::$mysql_binary . ' --no-defaults' . $ssl_flag,
[
'execute' => 'SELECT 1',
'send_to_shell' => false,
Expand All @@ -1241,8 +1244,9 @@ public function drop_db(): void {
if ( 'sqlite' === self::$db_type ) {
return;
}
$dbname = self::$db_settings['dbname'];
self::run_sql( self::$mysql_binary . ' --no-defaults', [ 'execute' => "DROP DATABASE IF EXISTS $dbname" ] );
$dbname = self::$db_settings['dbname'];
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "DROP DATABASE IF EXISTS $dbname" ] );
}

/**
Expand Down Expand Up @@ -1479,7 +1483,8 @@ public function install_wp( $subdir = '', $version = '' ): void {
if ( 'sqlite' === self::$db_type ) {
copy( "{$install_cache_path}.sqlite", "$run_dir/wp-content/database/.ht.sqlite" );
} else {
self::run_sql( self::$mysql_binary . ' --no-defaults', [ 'execute' => "source {$install_cache_path}.sql" ], true /*add_database*/ );
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "source {$install_cache_path}.sql" ], true /*add_database*/ );
}
} else {
$this->proc( 'wp core install', $install_args, $subdir )->run_check();
Expand All @@ -1492,7 +1497,8 @@ public function install_wp( $subdir = '', $version = '' ): void {
$mysqldump_binary = Utils\get_sql_dump_command();
$mysqldump_binary = Utils\force_env_on_nix_systems( $mysqldump_binary );
$support_column_statistics = exec( "{$mysqldump_binary} --help | grep 'column-statistics'" );
$command = "{$mysqldump_binary} --no-defaults --no-tablespaces";
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
$command = "{$mysqldump_binary} --no-defaults{$ssl_flag} --no-tablespaces";
if ( $support_column_statistics ) {
$command .= ' --skip-column-statistics';
}
Expand Down
Loading