Problem/Motivation
There are varying reports of xdebug breakpoints not stopping in web requests made from BrowserTestBase
tests (eg, code executed via drupalGet
, etc).
I am able to reproduce this locally running the latest 8.4.x, with PhpStorm xdebug connections set to 10, and xdebug.remote_autostart=1
. Normal debugging works just fine (including stepping into WebTestBase
web requests).
This is purportedly due to those tests utilizing PHPUnit's "run in separate process" functionality, which causes the code to be serialized php that is executed, and thus preventing IDEs from having appropriate code mappings.
There is a PR for PHPUnit to write these out to files so IDEs can do the appropriate mappings.
Comments
Comment #2
jhedstromComment #3
Mile23run-tests.sh
and Simpletest UI will launch all PHPUnit-based tests in a separate process, usingexec()
.run-tests.sh
does this so we can have concurrent test runs.If you use the
phpunit
tool, the test won't be running in a separate process unless it's annotated with@runInSeparateProcess
or@runTestsInSeparateProcesses
.So for debugging, try making sure there's no process annotation and do this:
$ SIMPLETEST_BASE_URL=http://localhost:8888/ ./vendor/bin/phpunit -c core/ --testsuite functional [specify your test here]
Comment #4
jhedstromYep, this appears to have been a passing thing that resolved itself. Breakpoints within web requests made from a test now properly stop.
Comment #5
benjy CreditAttribution: benjy at PreviousNext commentedJust tested this again and it doesn't work for me in the sub-requests from BTB, I don't think i've ever had it work with BTB but it used to with Simpletest.
Breakpoint lands as expected on
$this->drupalGet()
but never lands in index.php, running with./app/vendor/bin/phpunit path/to/MySampleTest.php
Inside of Vagrant, with the following vars set.
Using Drupal 8.4.x at
2dc6d91d60
Comment #6
marcoscanoA workaround I've been using is to set
xdebug.remote_autostart = 1
in apache's xdebug configuration whenever I want to debug drupal's code, and use it in cli's xdebug configuration, when I want to debug the test code itself.With this distinction, I haven't encountered any problems anymore.
Comment #7
benjy CreditAttribution: benjy at PreviousNext commentedThat seems to imply then that the environment variables/cookies are being lost in the requests the tests make if autostart works, no?
Comment #8
Mile23Running from run-tests.sh or phpunit?
See #3.
Comment #9
benjy CreditAttribution: benjy at PreviousNext commentedI gave an example of how I was running it in #5
./app/vendor/bin/phpunit path/to/MySampleTest.php
Comment #10
jibran@benjy does it work if you hack sub-request to add xdbug info in PhpStorm?
Comment #11
benjy CreditAttribution: benjy at PreviousNext commentedI tried this, but still no luck. I can see the cookie sent in the request but xdebug never connects.
Comment #13
jibranI faced the same issue as @benjy said. For all test suites where
$runTestInSeparateProcess = TRUE;
it ends up in\PHPUnit_Util_PHP_Default::runJob
where even if you hack the param passed to the$runtime
which is a path to binary the xdebug session will not start. At this point, I copied the$job
param value pasted it into a file and save it in docroot and executeed it with PHP CLI and viola it hit the breakpoint in the tests and if you have allowed multiple connections for debugger you can see all the requests.I think we need to fix phpunit test runner for
runTestInSeparateProcess
tests.Comment #14
Mile23Some overlap here: #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code
And a blog post here: http://mile23.com/content/how-phpunit-and-phpunit-bridge-make-false-pass...
Maybe this can be a conversation in Vienna.
Comment #16
pfrenssenIt looks like this problem is already solved in the latest version of PHPUnit: https://github.com/sebastianbergmann/phpunit/pull/2548
We are currently still on PHPUnit 4.x though which doesn't have this fix.
Comment #17
jibranSorry that PR is closed unmerged but in which PR this change is merged?
Comment #19
Bart Vanhoutte CreditAttribution: Bart Vanhoutte commentedIs this problem the same or related to breakpoints in KernelTestBase not working?
Comment #23
penance316 CreditAttribution: penance316 commentedI see no comments for a few years but it seems I am having this same issue.
drupal 8.9
PHP 7.4
phpunit 7.5.20
Is this still an issue for others?
My xdebug breakpoints are working fine for UNIT tests just not the tests extending BrowserTestBase.
Not sure if its helpful but when running UNIT tests I can use the xdebug function xdebug_break() fine but when trying that in the BrowserTestBase functional tests I get an error like "xdebug_break() is an undefined function" seeming to suggest that xdebug is not loaded correctly in that environment.
thanks all
Comment #25
gdeguzman CreditAttribution: gdeguzman commented#2850891-23: xdebug breakpoints not working in web requests from BrowserTestBase @penance316 I'm also having this issue on Drupal 8.9, PHP 7.3.25, PHPUnit 7.5.20, and xdebug 3. I'm attempting to run the debug through PHPStorm 2020.3. Breakpoints hit prior to my test (such as if I set them in BrowserTestBase), but as soon as it gets to the test actually running, the breakpoints in my actual test aren't hit. However, PHPUnit does go on to say that my test passes.
Like you, my Unit tests are working fine. I do believe it has to do with separate processes, but PHPStorm is set to 19 max simultaneous connections. It seems that something is being lost here in terms of xdebug being able to connect. Setting xdebug 3 options such as
discover_client_host=true
orstart_with_request=yes
has had no effect either.I'm unsure how widespread this issue is, as I seem to run into the same posts from a few years ago regarding this. I will post any updates I find here.
Comment #28
larowlanTagging this for tomorrow's sprint
Comment #32
super_romeo CreditAttribution: super_romeo commentedAny news?
There is no way to debug tests.