Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>Enable Xdebug in Behat tests</issue_title>
<issue_description>## Feature Request

Describe your use case and the problem you are facing

When working with the Behat tests, I'd like to be able to step debug the actual WP CLI + WordPress code which is being run.

Describe the solution you'd like

Add a WP CLI environmental variable to enable Xdebug, which would prepend any WP CLI commands run by Behat with Xdebug environmental variables to enable it.

WP_CLI_TEST_XDEBUG=true composer behat

In wp-cli/wp-cli/php/WP_CLI/Process.php:73 add:

if( getenv( 'WP_CLI_TEST_XDEBUG' ) ) {
  $this->command = "XDEBUG_CONFIG=\"idekey=WP_CLI_TEST_XDEBUG remote_connect_back=1 log_level=0\" XDEBUG_MODE=debug $this->command";
}

Drawbacks:

Definitely slower. And I seem to have to click play often, but maybe that's just a PhpStorm setting I've got wrong.

Alternatives:

Edit every Behat feature to add XDEBUG_CONFIG="idekey=WP_CLI_XDEBUG remote_connect_back=1 log_level=0" XDEBUG_MODE=debug as needed.

I seem to need XDEBUG_SESSION=1 sometimes – I certainly did not need it when I opened the issue.</issue_description>

Comments on the Issue (you are @copilot in this section)

@swissspidy We do something similar already when running tests with code coverage:

$with_code_coverage = (string) getenv( 'WP_CLI_TEST_COVERAGE' );
if ( \in_array( $with_code_coverage, [ 'true', '1' ], true ) ) {
$has_coverage_driver = ( new Runtime() )->hasXdebug() || ( new Runtime() )->hasPCOV();
if ( ! $has_coverage_driver ) {
throw new RuntimeException( 'No coverage driver available. Re-run script with `--xdebug` flag, i.e. `composer behat -- --xdebug`.' );
}
$coverage_require_file = self::$behat_run_dir . '/vendor/wp-cli/wp-cli-tests/utils/generate-coverage.php';
if ( ! file_exists( $coverage_require_file ) ) {
// This file is not vendored inside the wp-cli-tests project
$coverage_require_file = self::$behat_run_dir . '/utils/generate-coverage.php';
}
$current = getenv( 'WP_CLI_REQUIRE' );
$updated = $current ? "{$current},{$coverage_require_file}" : $coverage_require_file;
$env['WP_CLI_REQUIRE'] = $updated;
}

So this could be an easy addition.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@swissspidy
Copy link
Member

@copilot try again

1 similar comment
@swissspidy
Copy link
Member

@copilot try again

@swissspidy swissspidy closed this Dec 1, 2025
@swissspidy swissspidy deleted the copilot/enable-xdebug-in-behat-tests branch December 1, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable Xdebug in Behat tests

2 participants