3

In Laravel Homestead, I've been able to use Xdebug for unit tests, feature tests, poking around in the browser, etc.

But it hangs when I try to use Xdebug for Dusk (tests in tests/Browser folder).

I thought these questions might help, but I still haven't gotten it working:

I've tried various approaches, including:

export XDEBUG_CONFIG="idekey=netbeans-xdebug remote_connect_back=0 remote_host=10.0.2.2"
php artisan dusk

and

export XDEBUG_CONFIG="idekey=netbeans-xdebug remote_host=10.0.2.2"
php -dxdebug.remote_autostart=on -dxdebug.remote_connect_back=off -dxdebug.remote_host=10.0.2.2 artisan dusk

and more.

I've enabled the "Stop at First Line" debugging option in Netbeans, and Netbeans does successfully stop at the first executable PHP line in the artisan file.

Therefore I think export XDEBUG_CONFIG="idekey=netbeans-xdebug remote_connect_back=0 remote_host=10.0.2.2" is correctly set up.

But after I click the "play" button to allow the code to continue, Netbeans just says "netbeans-xdebug running" in the bottom right while the console just hangs with a cursor flashing under this line: php artisan dusk tests/Browser/ExampleTest.php

How do I need to change my usage of Xdebug for getting it to work in Dusk too?

Ryan
  • 22,332
  • 31
  • 176
  • 357
  • What IDE/Editor do you use (where you debug)? Maybe you need to increase max number of xdebug connections it can have at a time (No idea if NetBeans has it though). It's just a guess (never used Dusk) but Dusk might be creating separate processes .. so you may have situation when 2nd connection (sub-process) is waiting for 1st one (main) to finish... – LazyOne Feb 15 '19 at 15:32
  • @LazyOne Netbeans. And I don't think the problem relates to multiple connections. I just restarted my entire Win 10 PC and restarted the Laravel Homestead Vagrant virtual machine too, and I'm still unable to xdebug working. Thanks though. – Ryan Feb 15 '19 at 15:37
  • 2
    It probably doesn't work because Dusk executes the actual PHPUnit test in a separate process, so it doesn't know about `XDEBUG_CONFIG`. In principle, Dusk tests still work when you execute them directly (`phpunit tests/Browser/ExampleTest.php`). The main feature of `php artisan dusk` are custom `.env.dusk[.local]` files. If you don't require that, you can try calling them directly. Then Xdebug should behave the same way it does with all your other PHPUnit tests. – Jonas Staudenmeir Feb 15 '19 at 19:34
  • @JonasStaudenmeir Good to know. This has been helpful. Thank you! – Ryan Feb 15 '19 at 19:54
  • @JonasStaudenmeir If you write an answer below, I'll accept it. And maybe you know the answer to this next question (which if you want I can write as a new question post that you can add an answer to): The reason I'm trying to step through my Dusk tests is that one Dusk test successfully uses `loginAs`, but `loginAs` doesn't seem to work in another Dusk test, and the screenshot shows the blank Login form. How can I debug why `loginAs` won't work in one Dusk test while it does work in another nearly identical Dusk test? Thanks. – Ryan Feb 15 '19 at 20:09
  • @JonasStaudenmeir Hmm, I've narrowed it down to relating to https://github.com/spatie/laravel-permission or Backpack even though my database gets seeded properly with this user having all the max permissions. `loginAs` works if I temporarily edit the route group to not have certain middleware. – Ryan Feb 15 '19 at 20:16
  • 1
    Hard to say without seeing the code. If you create a minimal application and upload it somewhere, I'll take a look. – Jonas Staudenmeir Feb 15 '19 at 20:21

2 Answers2

4

It doesn't work because Dusk executes the actual PHPUnit test in a separate process, so it doesn't know about XDEBUG_CONFIG.

In principle, Dusk tests still work when you execute them directly (phpunit tests/Browser/ExampleTest.php). The main feature of php artisan dusk are custom .env.dusk[.local] files.

If you don't require that, you can try calling them directly. Then Xdebug should behave the same way it does with all your other PHPUnit tests.

Jonas Staudenmeir
  • 24,815
  • 6
  • 63
  • 109
0

As in my answer here, there is an option of running php -dxdebug.remote_enable=1 -dxdebug.remote_host=10.0.2.2 -dxdebug.remote_port=9000 -dxdebug.remote_handler=dbgp artisan my:command

You can also add those parameters to xdebug.ini like so:

zend_extension_ts = "./php/ext/php_xdebug<-version-number>.dll"
xdebug.remote_enable=1
xdebug.remote_host=10.0.2.2
; Port number must match debugger port number in NetBeans IDE Tools > Options > PHP
xdebug.remote_port=9000
xdebug.remote_handler=dbgp

xdebug.idekey=netbeans-xdebug (although I think it should work without this too)

Try removing break at first line option. Also try running debug directly from console with those options. And finally check that the correct port is set to listen in NetBeans and xdebug since that could cause problems too.

boroboris
  • 1,548
  • 1
  • 19
  • 32
  • Thank you for your answer, @Boroboris! However, it leaves me with the same problem as my question: Netbeans just says "netbeans-xdebug running" in the bottom right while the console just hangs with a cursor flashing. If I enable "Stop at First Line", your approach successfully does that, but then (just like in my question) it hangs indefinitely after I press Play to continue. Thanks anyway. – Ryan Feb 15 '19 at 19:58
  • did you try "normal" debugging? I mean does it stop anywhere else if you use some other command that's not dusk? – boroboris Feb 15 '19 at 19:59
  • Sure, your approach works for stepping through code of e.g. `\app\Console\Commands\MyCommand.php` (I just tried it), but that's not what I'm trying to do. I'm trying to step through a Dusk test to see why `loginAs` works in one Dusk test but not in another. Thanks. – Ryan Feb 15 '19 at 20:04