File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,23 @@ chmod +x ~/wp-cli/wp
147147WP_CLI_BIN_DIR=~ /wp-cli composer behat
148148` ` `
149149
150+ # ### Xdebug Step Debugging
151+
152+ You can enable Xdebug step debugging for Behat tests by setting the ` WP_CLI_TEST_XDEBUG` environment variable.
153+
154+ This is useful when you want to debug the actual WP-CLI + WordPress code that is being run during the tests.
155+
156+ ` ` ` bash
157+ WP_CLI_TEST_XDEBUG=true composer behat
158+ ` ` `
159+
160+ This will set the following Xdebug environment variables for all WP-CLI processes spawned by the tests:
161+ - ` XDEBUG_MODE=debug`
162+ - ` XDEBUG_SESSION=1`
163+ - ` XDEBUG_CONFIG=" idekey=WP_CLI_TEST_XDEBUG log_level=0" `
164+
165+ Note: You need to have Xdebug installed and your IDE configured to listen for debug connections.
166+
150167# ## Setting up the tests in Travis CI
151168
152169Basic rules for setting up the test framework with Travis CI:
Original file line number Diff line number Diff line change @@ -282,6 +282,17 @@ private static function running_with_code_coverage() {
282282 return \in_array ( $ with_code_coverage , [ 'true ' , '1 ' ], true );
283283 }
284284
285+ /**
286+ * Whether tests are currently running with Xdebug step debugging enabled.
287+ *
288+ * @return bool
289+ */
290+ private static function running_with_xdebug () {
291+ $ with_xdebug = (string ) getenv ( 'WP_CLI_TEST_XDEBUG ' );
292+
293+ return \in_array ( $ with_xdebug , [ 'true ' , '1 ' ], true );
294+ }
295+
285296 /**
286297 * @AfterSuite
287298 */
@@ -466,6 +477,12 @@ private static function get_process_env_variables(): array {
466477 $ env ['WP_CLI_REQUIRE ' ] = $ updated ;
467478 }
468479
480+ if ( self ::running_with_xdebug () ) {
481+ $ env ['XDEBUG_MODE ' ] = 'debug ' ;
482+ $ env ['XDEBUG_SESSION ' ] = '1 ' ;
483+ $ env ['XDEBUG_CONFIG ' ] = 'idekey=WP_CLI_TEST_XDEBUG log_level=0 ' ;
484+ }
485+
469486 $ config_path = getenv ( 'WP_CLI_CONFIG_PATH ' );
470487 if ( false !== $ config_path ) {
471488 $ env ['WP_CLI_CONFIG_PATH ' ] = $ config_path ;
You can’t perform that action at this time.
0 commit comments