How can you set-up PHP + xDebug + (x)Unit + Eclipse to work with breakpoints in unit tests?
-
22-08-2019 - |
Question
Have tried for quite some time to get this to work correctly but to no luck. Basically, I have Eclipse (3.3) with PHP Development Tools (PDT), and the PDT XDebug plugin as well as the SimpleTest eclipse plugin.
What I want to do is debug code invoked by SimpleTest unit tests. SimpleTest clearly can see XDebug, because I can generate code coverage reports, but it just won't stop on breakpoints.
Edit: Should add that XDebug and breakpoints work fine in eclipse, just not when invoked by SimpleTest
Has anyone set this up successfully? There's a lot of guff docs around and little in the way of useful information.
Thanks!
Solution
Make sure you have the right XDebug version for your version of PHP and add this at the very beginning of your php.ini file:
[xdebug]
zend_extension=full_path_to_your_xdebug.so
xdebug.default_enable=On
xdebug.remote_enable=On
xdebug.remote_handler="dbgp"
xdebug.remote_host="localhost"
xdebug.remote_port=9000
Then do an apachectl graceful
and a phpinfo
and make sure XDebug is present and active. If it is, everything should work fine. I know it does for me.
edit: I answered before reading the entire question.
before running the script you should set the environment variable;
export XDEBUG_CONFIG="idekey=session_name"
It might be possible to do this from php but i cannot test this:
putenv('XDEBUG_CONFIG="idekey=session_name"');
You should make sure that the php binary you are using has the XDebug extension loaded, on my system the apache module has it, but the default CLI interpreter does not, but I run different versions on purpose.
There's some good documentation here
OTHER TIPS
To go further on Kris' answer, If you manage your production and development environments on the same Server, It's a good idea to relegate your xdebug settings either to a php include
or to those of your virtualhosts
which are dedicated to dev
or testing
environments :
the syntax for virtualhosts is
<virtualHost ....> (...) # Xdebug ENV php_flag xdebug.auto_trace on php_flag xdebug.idekey session_name php_flag xdebug.profiler_enable_trigger 1 php_flag xdebug.(...) (...)