-
Notifications
You must be signed in to change notification settings - Fork 26
Add WP_CLI_TEST_XDEBUG environment variable for step debugging in Behat tests #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f802ab2
21b82d3
7618a3a
5446612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,6 +278,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 ); | ||
| } | ||
|
|
||
| public static function merge_coverage_reports(): void { | ||
| if ( ! self::running_with_code_coverage() ) { | ||
| return; | ||
|
|
@@ -459,6 +470,35 @@ private static function get_process_env_variables(): array { | |
| $env['WP_CLI_REQUIRE'] = $updated; | ||
| } | ||
|
|
||
| if ( self::running_with_xdebug() ) { | ||
| $xdebug_mode = getenv( 'XDEBUG_MODE' ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially I was thinking using |
||
| if ( false !== $xdebug_mode && '' !== $xdebug_mode ) { | ||
| $modes = array_filter( | ||
| array_map( | ||
| 'trim', | ||
| explode( ',', $xdebug_mode ) | ||
| ), | ||
| static function ( $mode ) { | ||
| return '' !== $mode; | ||
| } | ||
| ); | ||
| if ( ! in_array( 'debug', $modes, true ) ) { | ||
| $modes[] = 'debug'; | ||
| } | ||
| $env['XDEBUG_MODE'] = implode( ',', $modes ); | ||
| } else { | ||
| $env['XDEBUG_MODE'] = 'debug'; | ||
| } | ||
|
|
||
| if ( false === getenv( 'XDEBUG_SESSION' ) ) { | ||
| $env['XDEBUG_SESSION'] = '1'; | ||
| } | ||
|
|
||
| if ( false === getenv( 'XDEBUG_CONFIG' ) ) { | ||
| $env['XDEBUG_CONFIG'] = 'idekey=WP_CLI_TEST_XDEBUG log_level=0'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...which makes me think this line is wrong. If a user has defined these in I'm starting to think the commit I wrote & mentioned which I dismissed might be a good idea after all: BrianHenryIE@951eb46 |
||
| } | ||
| } | ||
|
|
||
| $config_path = getenv( 'WP_CLI_CONFIG_PATH' ); | ||
| if ( false !== $config_path ) { | ||
| $env['WP_CLI_CONFIG_PATH'] = $config_path; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think return type
: boolis acceptable since PHP 7.I hate the WPCS rule that makes me define it twice.