Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to debug PhpUnit tests with --process-isolation option?

For unittest

class SampleTest extends PHPUnit_Framework_TestCase
{
    public function testBreakpoint()
    {
        $a = 18;
    }
}

with breakpoint on line 5 "$a = 18;",

  • Xdebug v2.1.0,
  • PHPUnit 3.6.10,
  • PHP 5.3.6,
  • ubuntu 10.11

Running unittest with NO --process-isolation option stops script execution on the line 5, as expected. Running the same configuration WITH --process-isolation option does not stop execution on line 5.

The option --process-isolation runs every test in new process using 'proc_open' in runJob function in https://github.com/sebastianbergmann/phpunit/blob/3.6/PHPUnit/Util/PHP.php

Tested with PhpStorm 3 and vim 7 with debugger plugin. It allows to debug PHPUnit itself, but not testcases.

Is there any way to debug the child process created by PhpUnit using Xdebug? may be Zend Debugger?

like image 784
Alex Blex Avatar asked Mar 21 '12 14:03

Alex Blex


3 Answers

As stated in the comments on the question. The issue is that PHP Storm didn't support multiple parallel debugging sessions.

like image 197
SamHennessy Avatar answered Oct 15 '22 05:10

SamHennessy


Go into PHPStorm Project Settings - PHP - Debug and set Xdebug to "force break at first line when script is outside the project".

It should break on some main() method and if you step over a couple of times (or press resume), it will reach your test.

like image 36
Artjom Kurapov Avatar answered Oct 15 '22 06:10

Artjom Kurapov


This isn't a perfect answer, but you can surround any block of code with xdebug_start_trace() and xdebug_stop_trace() calls to generate a stack trace for a targeted block of code. I've used this to see exactly what it happening at specific points in my unit tests when testing other peoples' code.

class SampleTest extends PHPUnit_Framework_TestCase
{
    public function testBreakpoint()
    {
        xdebug_start_trace('/tmp/testBreakPointTrace');
        $a = 18;
        xdebug_stop_trace();
    }
}

Just keep in mind that any failures will cause PHPUnit's exception handler to step in and cause the stack trace to look a little strange. If you are getting an error, you can get a clean trace by adding an exit; call right after xdebug_stop_trace:

class SampleTest extends PHPUnit_Framework_TestCase
{
    public function testBreakpoint()
    {
        xdebug_start_trace('/tmp/testBreakPointTrace');
        $a = 18;
        xdebug_stop_trace();
        exit;
    }
}
like image 1
Bryan Geraghty Avatar answered Oct 15 '22 07:10

Bryan Geraghty