Repository navigation
Add WP_CLI_TEST_XDEBUG environment variable for step debugging in Behat tests - #289
Conversation
…ugging in Behat tests Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@BrianHenryIE wanna test this one? |
|
I took a look at using For visual: Full xdebug_info output (expand)Partial xdebug_info output: It accepts a % php -r "print_r(xdebug_info('mode'));"
Array
(
[0] => develop
)% XDEBUG_MODE=debug php -r "print_r(xdebug_info('mode'));"
Array
(
[0] => debug
)It seems there is only No tests in xdebug/xdebug suggested any other valid values. I wrote the code to allow specifying the But after reading a bit more I don't know if it's worthwhile: https://xdebug.org/docs/all_settings#idekey
https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html#updatingPhpIni
I've still to actually run the code to test it but it reads like how I remember doing it before. TODO:
|
Personally I'd want separate options, to have more flexibility and not accidentally slow down my whole test suite if I want to only debug the test runner and not the commands executed by it.
Should be reasonable to support only Xdebug 3 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| $env['XDEBUG_MODE'] = 'debug'; | ||
| $env['XDEBUG_SESSION'] = '1'; | ||
| $env['XDEBUG_CONFIG'] = 'idekey=WP_CLI_TEST_XDEBUG log_level=0'; | ||
| $xdebug_mode = getenv( 'XDEBUG_MODE' ); |
There was a problem hiding this comment.
Initially I was thinking using getenv() wouldn't be enough, but if XDebug's mode is set already in the php.ini then it should pass through anyway.
| } | ||
|
|
||
| if ( false === getenv( 'XDEBUG_CONFIG' ) ) { | ||
| $env['XDEBUG_CONFIG'] = 'idekey=WP_CLI_TEST_XDEBUG log_level=0'; |
There was a problem hiding this comment.
...which makes me think this line is wrong.
If a user has defined these in php.ini (I've never done that myself) then this will apply defaults that are incorrect.
I'm starting to think the commit I wrote & mentioned which I dismissed might be a good idea after all: BrianHenryIE@951eb46
BrianHenryIE
left a comment
There was a problem hiding this comment.
😕 I haven't yet run this end to end. Your December 4 comments were reasonable. You didn't reply to the suggestion of having a wp-cli.yml config option and it's totally reasonable to address that in its own PR when/if needed.
| * | ||
| * @return bool | ||
| */ | ||
| private static function running_with_xdebug() { |
There was a problem hiding this comment.
I think return type : bool is acceptable since PHP 7.
I hate the WPCS rule that makes me define it twice.
Thanks for the initial review! And sorry for not replying to that :) A behat.yml config is interesting, but needs testing to verify that Behat isn't confused by such a setting. wp-cli.yml is for WP-CLI runtime configs, not testing, so not the right place IMO |
Resolves the conflict with the PHP tuning added on main, which switches Xdebug off for the launched processes: the Xdebug variables are now merged after it, so that step debugging still works. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
Add the debug mode to the modes set through XDEBUG_MODE or php.ini instead of replacing them, and keep the coverage mode when code coverage is collected. Append the lowered log level to a user's XDEBUG_CONFIG rather than leaving it out, as the warnings Xdebug prints when no IDE is listening make scenarios fail, and drop the IDE key, which only matters for DBGp proxies and overrode the one set in php.ini. Don't use Docker when step debugging, as the containers would neither receive the variable nor reach the IDE. Move the documentation into the README partial and add unit tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
`ReflectionMethod::setAccessible()` is deprecated as of PHP 8.5, which PHPStan reports even behind the PHP version check. A closure bound to the FeatureContext scope works on all supported PHP versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
Adds support for enabling Xdebug step debugging when running Behat tests, allowing developers to debug the actual WP-CLI + WordPress code executed during tests.
Changes:
running_with_xdebug()method inFeatureContext.php(mirrors existingrunning_with_code_coverage()pattern)XDEBUG_MODE:debugis added to the modes set throughXDEBUG_MODEorxdebug.mode(minusoff), pluscoveragewhenWP_CLI_TEST_COVERAGEis onXDEBUG_SESSION=1, unless already setXDEBUG_CONFIG:log_level=0is appended unless a log level is set, so "Could not connect to debugging client" warnings don't end up in the checked outputbin/run-behat-testsruns without Docker when step debugging, like it does for coverage.readme-partials/USING.mdand README.mdtests/tests/TestXdebugEnv.phpUsage:
Avoid parallel workers while step debugging.
Fixes #257