2

I'm having a really difficult time trying to get XDebug working with my functional tests that extend from BrowserTestBase.

Does anyone have a working configuration in place for this?

I'm using PHPStorm (version 2016.2) for debugging and already have a working XDebug setup for standard unit tests. I've been initiating the tests from PHPStorm directly, but would certainly be happy running them from a terminal outside of PHPStorm if it works!

Here's what I've tried for running out outside of PHPStorm in a normal terminal:

export SIMPLETEST_BASE_URL=http://drupal8.dd:8083
export XDEBUG_CONFIG="idekey=PHPSTORM"
vendor/bin/phpunit --configuration core/phpunit.xml.dist /Users/bosborne/Projects/drupal8/modules/cas/tests/src/Functional/CasAdminSettingsTest.php

The tests run but my breakpoints are ignored.

7

BrowserTestBase and KernelTestBase use phpunit's 'run in separate process' feature which generates a new temporary php file from a template and then executes that. The output is provided as serialized php object which is then read back into the main thread an unserialized to yield the results.

So at present that makes using Xdebug fairly difficult.

We probably should open an issue to look at shipping our own template that support Xdebug.

In the meantime my suggestion would be to use outputting, you can use the standard approaches like var_export, print_r, echo etc or you can use $this->htmlOutput($something_you_need_to_debug); which then shows up amongst the other HTML output.

Then run your tests with -printer="\Drupal\Tests\Listeners\HtmlOutputPrinter"

This requires the BROWSERTEST_OUTPUT_DIRECTORY environment variable to be set, see core's phpunit.xml.dist for info on how to configure that.

  • Ok, thanks for verifying I'm not crazy, I appreciate the help and alternative approaches. – Brian Sep 11 '16 at 20:57
  • Actually BrowserTestBase and KernelTestBase aren't run in separate processes by default. run-tests.sh does that to enable concurrent test runs to speed things up. You want to use the phpunit runner instead, which won't run a test in a separate process unless you tell it to. – paul-m Apr 18 '17 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.