7

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 ?

Nealv
  • 6,481
  • 6
  • 52
  • 83
  • Have you tried clicking on "Debug" button instead of "Run"? As for xdebug configuration -- same as for "ordinary" php code. – LazyOne Dec 17 '14 at 09:42
  • 2
    Yes I have. After I configured behat in phpstorm and added export XDEBUG_CONFIG="idekey=PHPSTORM" to my bash_profile it seems to work. – Nealv Dec 17 '14 at 10:51
  • I'm just trying to do exactly the same, but can't get it working. Could you explain "added export XDEBUG_CONFIG="idekey=PHPSTORM" to my bash_profile" a bit further? Which bash profile and where to put it? Thanks – Chris Mar 26 '15 at 15:23
  • Are you using mac ? for me my bash profile is in: /Users/myUserName/.bash_profile There I just added a line: export XDEBUG_CONFIG="idekey=PHPSTORM" – Nealv Mar 27 '15 at 10:58
  • Thanks Nealv, I think I have a different configuration problem. Must have something to do with my project setup (Files locally, Deployment to a mounted Server). – Chris Mar 30 '15 at 12:26
  • This question needs to be clarified: are you trying to debug steps only or also want to debug the system under test? I.e., if Mink CURLs your website, do you want to step through the website's scripts (SUT) as well? – Alex Skrypnyk May 29 '17 at 00:17

1 Answers1

5

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)

Fodagus
  • 486
  • 4
  • 13
  • I cannot stress enough how important it is to set `xdebug.remote_connect_back=0` to make sure that `xdebug.remote_host` and `xdebug.remote_port` values are respected. If this is not set to `0`, than you will only be able to debug behat steps, but not the system under test. – Alex Skrypnyk May 29 '17 at 00:50