Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 27
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
f802ab221b82d37618a3a54466122e0ba0aee5ccbcFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -308,6 +308,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; | ||
| @@ -506,6 +517,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'; | ||
| ||
| } | ||
| } | ||
| $config_path = getenv( 'WP_CLI_CONFIG_PATH' ); | ||
| if ( false !== $config_path ) { | ||
| $env['WP_CLI_CONFIG_PATH'] = $config_path; | ||
Uh oh!
There was an error while loading. Please reload this page.
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.