Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable XDebug in Behat

I am using behat+mink. I wrote some features and am now running tests.

How can I enable xdebug to to stop on breakpoints in phpstorm when running behat tests ?

like image 925
Nealv Avatar asked Dec 17 '14 09:12

Nealv


1 Answers

I have not tried this with Mink yet, but this is configuration that allows me to step through debugging of behat (with behat running on a remote server):

Configure your server with x-debug

xdebug config

Of note, since this is commandline, you need to edit the cli config under /etc/php5/cli/conf.d/20-xdebug.ini.

  • Set remote_host to the ip of the computer you're using PHPSTORM from
  • Set autostart = 1
  • Disable connect_back, you will initiate debugging from the server so there is nothign to connect back to

You can also do this without editing your ini by exporting values as env variables, just remember to do this each time you start a new shell (or add to your .bash_profile file):

export XDEBUG_CONFIG="remote_host=<YOUR IP>"

Configure PHPStorm's Debugger

It seems by default, PHPStorm doesn't understand remote-cli scripts, so we need to add a configuration that tells it to expect a CLI script to trigger xdebug

  1. Open the Run Menu and select "Edit Configurations"
  2. Click the Green "+" to to add a new configuration and select "PHP Remote Debug"
  3. Name the Configuration (E.G. MyServer-Behat) Create new Debug Configuration
  4. Under the Servers: menu, select your remote server.
    1. If you haven't configured your remote server yet, then do this by clicking the "..." button on the right
    2. Click the Green "+" to add a server configuration. Give it a name (E.G. MyServer) and fill in it's address under Host
    3. Configure it's Path Mappings. This is important if the path to your source files is different on your PHPStorm computer from your server. You can see in my example that i'm relating my local checkout (~/Work/Symfony/) to my server install (/var/www/). I specifically added mappings for src, bin, web, app, and vendor by clicking in the space to the right under "Absolute path on the server" and typing in the path. I had issues just mapping the root's, so I had to add these paths to get my debugger to work. enter image description here

Debug!

Once that is setup, select your configuration from the drop down in the debugging tool bar and click the bug icon (you can also use the Run menu) to start the debugger listening. This is similar to the default Telephone Button (circled in yellow), but it tells PHPStorm to use your new configuration. enter image description here

Now simply run behat like you normally would from your server and your debugger should connect and stop on any breakpoints you've placed.

If you're having doubts about if it's working or not, try toggling the "Break on First Line" in the Run menu, as this should make the debugger break immediately when you run behat (in the bin/behat file)

like image 142
Fodagus Avatar answered Sep 24 '22 01:09

Fodagus