Skip to content
Draft
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ chmod +x ~/wp-cli/wp
WP_CLI_BIN_DIR=~/wp-cli composer behat
```

#### Xdebug Step Debugging

You can enable Xdebug step debugging for Behat tests by setting the `WP_CLI_TEST_XDEBUG` environment variable.

This is useful when you want to debug the actual WP-CLI + WordPress code that is being run during the tests.

```bash
WP_CLI_TEST_XDEBUG=true composer behat
```

This will set the following Xdebug environment variables for all WP-CLI processes spawned by the tests:
- `XDEBUG_MODE=debug`
- `XDEBUG_SESSION=1`
- `XDEBUG_CONFIG="idekey=WP_CLI_TEST_XDEBUG log_level=0"`

Note: You need to have Xdebug installed and your IDE configured to listen for debug connections.

### Setting up the tests in Travis CI

Basic rules for setting up the test framework with Travis CI:
Expand Down
17 changes: 17 additions & 0 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ private static function running_with_code_coverage() {
return \in_array( $with_code_coverage, [ 'true', '1' ], true );
}

/**
* Whether tests are currently running with Xdebug step debugging enabled.
*
* @return bool
*/
private static function running_with_xdebug() {
$with_xdebug = (string) getenv( 'WP_CLI_TEST_XDEBUG' );

return \in_array( $with_xdebug, [ 'true', '1' ], true );
}

/**
* @AfterSuite
*/
Expand Down Expand Up @@ -466,6 +477,12 @@ private static function get_process_env_variables(): array {
$env['WP_CLI_REQUIRE'] = $updated;
}

if ( self::running_with_xdebug() ) {
$env['XDEBUG_MODE'] = 'debug';
$env['XDEBUG_SESSION'] = '1';
$env['XDEBUG_CONFIG'] = 'idekey=WP_CLI_TEST_XDEBUG log_level=0';
}

$config_path = getenv( 'WP_CLI_CONFIG_PATH' );
if ( false !== $config_path ) {
$env['WP_CLI_CONFIG_PATH'] = $config_path;
Expand Down
Loading