Debugging PHPUnit tests in Eclipse PDT with XDebug on Debian GNU/Linux

Wow, this was complicated!

Make sure PHP, Xdebug, etc. are installed:

 # apt-get install php php5-xdebug php5-curl php5-mysql php5-gd

Install Eclipse:

 # apt-get install eclipse

To install PHP Developer Tools in Eclipse: Open Eclipse, click Help -> Install New Software…

Work with:

Select PHP Development Tools / PHP Development Tools (PDT) and install.

Create a new PHP project in Eclipse.

Download PHPUnit into your project folder, e.g.:

 $ cd ~/workspace/new-project
 $ wget
 $ chmod +x phpunit.phar
 $ cp phpunit.phar /usr/local/bin/phpunit

In your Eclipse PHP project right-click on your project and select “Include Path” -> “Configure Include Path”.

Click “Libraries” -> “Add External PHARs” then add “phpunit.phar” (in your project’s workspace).

In Eclipse click “Run” -> “Debug Configurations”. Click “PHP CLI Application” and then “New”. Enter the PHP Script name as “PHPUnit” with Project default PHP: PHP CLI (Xdebug 5.4.4 CLI). Set the PHP file as “/project-name/phpunit.phar”.

Edit your php.ini file, e.g.:

 # vim /etc/php5/cli/php.ini

And make sure to specify an xdebug configuration (append to end of file is OK):


xdebug.default_enable = on

xdebug.remote_mode = "req"
xdebug.remote_connect_back = on
xdebug.remove_log = /tmp/xdebug.log

Make sure you have a phpunit.xml file next to phpunit.phar in your workspace, e.g.:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
    <testsuite name="Tests">
       <directory suffix="Test.php">test</directory>

Make sure there is one test in your test directory, e.g. /project-name/test/MyTest.php

class MyTest extends PHPUnit_Framework_TestCase {

  public function setUp() {
    //require_once( __DIR__ . '/../src/example.php' );

  public function testExample() {
    $this->assertSame( '1', '1' );

Double-click in the sidebar next to $this->assertSame to put a breakpoint there.

Then in Eclipse on the toolbar at the top is a little ‘bug’ icon, click ‘down’ next to that and debug ‘PHPUnit’.

Your unit tests should run in PHPUnit and break into the PHP debugger in Eclipse.

Did that work for you? Let me know!

Leave a Reply