Can I debug PhpUnit tests with the --process-isol option?

For unittest

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

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

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

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

The process isolation option runs each test in a new process using the proc_open function in the runJob function at https://github.com/sebastianbergmann/phpunit/blob/3.6/PHPUnit/Util/PHP.php

Tested with PhpStorm 3 and vim 7 with a debugger plugin. This allows you to debug PHPUnit itself, but not test ones.

, PhpUnit, Xdebug? Zend Debugger?

+5
3
0

PHPStorm - PHP - Xdebug " , script ".

main().. ( "" ),

+2

This is not an ideal answer, but you can surround any block of code with xdebug_start_trace () and xdebug_stop_trace () with calls to create a stack trace for the target code block. I used this to see exactly what happens at certain points in my unit tests when testing other people's 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 the PHPUnit exception handler to intervene and make the stack trace look a little strange. If you get an error message, you can get a clean trace by adding output; call immediately after xdebug_stop_trace:

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

All Articles