How to debug behat features using xdebug?
Asked Answered
S

2

6

Having hard time with Behat, cent find the way to debug (php/xdebug using breakpoints and steps). Does anybody have experience or maybe there is better way to do the same?

Edited:

"behat/mink": "*",
"behat/mink-extension": "*",
"behat/mink-zombie-driver": "*@dev",
"behat/mink-selenium2-driver": "*"

Testing regular feature on website.

Success answered 24/4, 2014 at 17:44 Comment(4)
What do you test with Behat? And do you use Mink ?Vadnais
Yes I use Mink and testing website form submit. Basically missing the place to put breakpoints to see how website reacts since features are taken from feature text file.Success
@Aram, did you figure out how to achieve this? Is this possible or not?Confiteor
Nope, haven't figured out yet.Success
W
2

You should set the following environment variable before launching your tests:

XDEBUG_CONFIG="XDEBUG_SESSION_START="

It works for me.

We answered 14/8, 2014 at 10:53 Comment(4)
could you please provide more information? I tried with $var = "XDEBUG_SESSION_START="; putenv("XDEBUG_CONFIG=$var"); but it didnt workWithershins
What you are talking about is how to debug any php script from command line which works well when debugging own context classes, but does not help when debugging feature and need to hold between steps. I've seen plugin for cucumber js for node which hung and wait for your input from command line between steps.Success
This is basically solution but you will need to find and set breakpoints on Mink Context methods.Success
@serge-hardy, where/how are you setting this? In the .php script or in PHP.INI?Locust
P
0
  1. In php.ini* find xdebug section
  2. Add another line saying "xdebug.remote_autostart=1" Be ready to comment this line out after you're done with cli testing / debugging.

* the xdebug section may be harder to locate:

  1. there may be multiple php.ini files, e.g. one for cli, another for apache.
  2. there may be multiple php versions
  3. the xdebug may have it's separate file, e.g. on some linuxes it could be under /etc/php/7.0/cli/conf.d/20-xdebug.ini

Once commenting the autostart gets annoying in the long run, it may be worth investing in some parametrized switch or separate ini files. But I would give myself a week of annoyance before going down this path.

Pursuivant answered 10/5, 2017 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.