7
votes

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

4
If you are able to debug normal scripts in CLI mode in PhpStorm .. then do the same but with PHPUnit: create Run/Debug Configuration of PHPUnit type, fill all required fields so you can run it in PHPUnit .. and instead of "Run" use "Debug" button.LazyOne

4 Answers

7
votes

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
2
votes

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

0
votes

In Ubuntu to debug CLI I found the only way to get it to work was to add the following to your ~/.bashrc file

export PHP_IDE_CONFIG='serverName=localhost'
export XDEBUG_CONFIG='idekey=PHPSTORM'

Replace idekey=?? to 11854 in your example. Be sure to start a new console session so the vars are used.

0
votes

I'm trying here a very different setup. I run my applications inside dockers and I have a container very similar to containers running on production. So, to run php with xdebug in my development environment, I had to setup an alias with xdebug params and the PHPStorm variable.

$ alias php=`which php`' \
    -d xdebug.idekey=xdbg \
    -d xdebug.remote_enable=1 \
    -d xdebug.remote_connect_back=1 \
    -d xdebug.remote_autostart=1 \
    -d xdebug.remote_port=9000 \
    -d xdebug.remote_host=172.17.0.1 \
    -d xdebug.remote_handler=dbgp'

$ export PHP_IDE_CONFIG="serverName=localapp.docker"

After this not beautiful trick, I could put breakpoints on PHPStorm and run phpunit from command line.

$ php ../../bin/phpunit --verbose

All commands above was run inside container. The localapp.docker is the address of my container and is hardcoded /etc/hosts of host.