Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to debug phpunit unit test on cli using xdebug fails

I'm using PHPStorm which is configured to use xDebug (I can debug via the web browser just fine)

I run the debugger in PHPStorm which has the idekey of 11854 and I'm trying to debug a unit test, and I've set the breakpoints properly

so I executed this command through the cli:

phpunit -d xdebug.profiler_enable=on -d xdebug.idekey=11854 --filter testFunction s_function/sFunctionTest.php

Nonetheless, it wouldn't debug at the breakpoint accordingly...

when I tried executing this in the test script:

error_log(ini_get('xdebug.profiler_enable'));
error_log(ini_get('xdebug.idekey'));

it would reveal that xdebug.profiler_enable is 0 and xdebug.idekey is just my username.

What did I do wrong and how can I get xdebug to work on phpunit through the cli

like image 346
pillarOfLight Avatar asked Jun 14 '13 17:06

pillarOfLight


People also ask

Why is Xdebug not working?

Xdebug cannot connect to PhpStorm This means that Xdebug tries to connect to the host and can't make the connection. To fix the issue, set xdebug. remote_connect_back=0 ( xdebug. discover_client_host=false for Xdebug 3) and make sure that xdebug.

How do I debug Xdebug?

Press F5 to start the debugger. Click the new XDebug Helper extension and click the Debug option. Finally, refresh the page in the browser to let VSCode react and start the debugging process.

How do I enable Xdebug log?

Enable Xdebug logging by adding the following line into php. ini: xdebug. remote_log=/log_path/xdebug.


2 Answers

You are just setting arguments to phpunit, not to PHP. The following should do what you want:

php -d xdebug.profiler_enable=on -d xdebug.idekey=11854 `which phpunit` --filter testFunction s_function/sFunctionTest.php
like image 128
Derick Avatar answered Oct 16 '22 21:10

Derick


The xdebug docs give a solution that looks simpler...

export XDEBUG_CONFIG="idekey=session_name"
php myscript.php

Once that variable is set, you can run your scripts from the command line as normal (for that SSH session) and PHP will use this configuration.

Also of note:

You can also configure the xdebug.remote_host, xdebug.remote_port, xdebug.remote_mode and xdebug.remote_handler in this same environment variable as long as you separate the values by a space

like image 2
Reilly Sweetland Avatar answered Oct 16 '22 20:10

Reilly Sweetland