Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions features/db-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ Feature: Check the database
Given a WP install

When I try `wp db check --defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) %s#
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) %s#

When I try `wp db check --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) --no-defaults %s#

When I try `wp db check --no-defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysqlcheck|mariadb-check) --no-defaults %s#
Comment on lines +157 to +163

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Cover the new missing-binary error paths with Behat tests.

  • features/db-check.feature#L157-L163: add a scenario that disables both check binaries and asserts the expected error.
  • features/db-export.feature#L143-L149: add a scenario that disables both dump binaries and asserts the expected error.

As per coding guidelines, all new features and bug fixes must include Behat acceptance tests following existing feature-test patterns.

📍 Affects 2 files
  • features/db-check.feature#L157-L163 (this comment)
  • features/db-export.feature#L143-L149
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@features/db-check.feature` around lines 157 - 163, Add Behat scenarios
covering missing database-check binaries: in features/db-check.feature lines
157-163, disable both mysqlcheck and mariadb-check and assert the expected
error. Also update features/db-export.feature lines 143-149 with the
corresponding scenario disabling both dump binaries and asserting its expected
error, following the existing feature-test patterns.

Source: Coding guidelines


@require-mysql-or-mariadb
Scenario: Empty DB credentials should not cause empty parameter errors
Expand Down
6 changes: 3 additions & 3 deletions features/db-export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ Feature: Export a WordPress database
Given a WP install

When I try `wp db export --defaults --debug`
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump)#
Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump)#

When I try `wp db export --debug`
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump) --no-defaults#
Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump) --no-defaults#

When I try `wp db export --no-defaults --debug`
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump) --no-defaults#
Then STDERR should match #Debug \(db\): Running initial shell command: /([^/]+/)+(mysqldump|mariadb-dump) --no-defaults#

@skip-sqlite
@skip-windows
Expand Down
34 changes: 27 additions & 7 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,14 @@ public function check( $_, $assoc_args ) {
return;
}

$check_command = Utils\get_sql_check_command();
if ( '' === $check_command ) {
WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' );
}

$command = sprintf(
'/usr/bin/env %s%s %s',
Utils\get_sql_check_command(),
'%s%s %s',
$check_command,
$this->get_defaults_flag_string( $assoc_args ),
'%s'
);
Expand Down Expand Up @@ -347,9 +352,14 @@ public function optimize( $_, $assoc_args ) {
return;
}

$check_command = Utils\get_sql_check_command();
if ( '' === $check_command ) {
WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' );
}

$command = sprintf(
'/usr/bin/env %s%s %s',
Utils\get_sql_check_command(),
'%s%s %s',
$check_command,
$this->get_defaults_flag_string( $assoc_args ),
'%s'
);
Expand Down Expand Up @@ -408,9 +418,14 @@ public function repair( $_, $assoc_args ) {
return;
}

$check_command = Utils\get_sql_check_command();
if ( '' === $check_command ) {
WP_CLI::error( 'The mysqlcheck or mariadb-check binary is not available.' );
}

$command = sprintf(
'/usr/bin/env %s%s %s',
Utils\get_sql_check_command(),
'%s%s %s',
$check_command,
$this->get_defaults_flag_string( $assoc_args ),
'%s'
);
Expand Down Expand Up @@ -756,7 +771,12 @@ public function export( $args, $assoc_args ) {
$assoc_args['result-file'] = $result_file;
}

$mysqldump_binary = Utils\force_env_on_nix_systems( Utils\get_sql_dump_command() );
$dump_command = Utils\get_sql_dump_command();
if ( '' === $dump_command ) {
WP_CLI::error( 'The mysqldump or mariadb-dump binary is not available.' );
}

$mysqldump_binary = $dump_command;

$support_column_statistics = $this->command_supports_option( $mysqldump_binary, 'column-statistics' );

Expand Down
Loading