Skip to content

Instantly share code, notes, and snippets.

@pavlakis
Last active August 5, 2016 14:15
Show Gist options
  • Save pavlakis/b58e903bc10c0754ccf2e3486618faaa to your computer and use it in GitHub Desktop.
Save pavlakis/b58e903bc10c0754ccf2e3486618faaa to your computer and use it in GitHub Desktop.
Remote CLI Xdebug through PHPUnit and Vagrant

Remote CLI Xdebug through PHPUnit and Vagrant

For more information on remote debugging see Derick Rethan's 2011 post

For info on debugging PHP CLI with PhpStorm see Gary Hockin's post - DEBUGGING PHP COMMAND LINE (WITH PHP STORM & XDEBUG)

tl;dr

Connect to vagrant using an ssh tunnel and run phpunit through there. The same process applies when running a normal PHP CLI script.

Create an ssh tunnel

ssh -R 9000:localhost:9000 [email protected] password is vagrant

As a work around on the issue with Path Mappings (with PhpStorm), download phpunit.phar and put it in the tests folder.

Run the following from within Vagrant

Go to the tests directory

cd /var/www/mysite/tests

Add the environment variable

export XDEBUG_CONFIG="idekey=PhpStorm1"

Run the command

php phpunit.phar -c phpunit.xml Domain/User/UserTest.php

PhpStorm

As long as you've set PhpStorm to listen to port 9000 and have started listening for PHP Debug Connections, the only thing remaining to set is the path mappings. Also (very important) becuse we're using a phar file, PhpStorm will show this warning:

Can't compute source position. The script 'phpunit.phar' isn't associated with any text file type.

To overcome that, just set a breakpoint and press play.

When done unset the environment variable

unset XDEBUG_CONFIG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment