是否可以使用-process-isolation选项调试PhpUnit测试?

时间:2022-10-15 19:41:15

For unittest

对于unittest

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

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

对于第5行上的断点“$a = 18;”

  • Xdebug v2.1.0,
  • Xdebug v2.1.0,
  • PHPUnit 3.6.10,
  • PHPUnit)3.6.10,
  • PHP 5.3.6,
  • PHP 5.3.6,
  • ubuntu 10.11
  • 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.

如预期的那样,在没有进程隔离选项的情况下运行unittest将停止第5行上的脚本执行。使用-process-isolation选项运行相同的配置不会停止第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

在runJob函数中,使用“proc_open”在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.

使用PhpStorm 3和vim7测试,使用调试器插件。它允许调试PHPUnit本身,但不允许调试testcase。

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

是否有任何方法可以使用Xdebug调试由PhpUnit创建的子进程?可能是Zend调试器吗?

3 个解决方案

#1


1  

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

正如在对这个问题的评论中所述。问题是,PHP Storm不支持多个并行调试会话。

#2


3  

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

进入PHPStorm项目设置—PHP—调试,并将Xdebug设置为“脚本在项目外部时在第一行强制中断”。

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

它应该在主()方法上失效。如果你跨过几次(或按下简历),它就会到达你的测试

#3


1  

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.

这并不是一个完美的答案,但是您可以使用xdebug_start_trace()和xdebug_stop_trace()来包围任何代码块,以生成针对目标代码块的堆栈跟踪。我已经使用它来确切地看到在我的单元测试中测试其他人的代码时发生了什么。

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:

只要记住,任何失败都会导致PHPUnit的异常处理程序介入,并使堆栈跟踪看起来有点奇怪。如果出现错误,可以通过添加退出来获得干净的跟踪;叫xdebug_stop_trace之后:

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

#1


1  

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

正如在对这个问题的评论中所述。问题是,PHP Storm不支持多个并行调试会话。

#2


3  

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

进入PHPStorm项目设置—PHP—调试,并将Xdebug设置为“脚本在项目外部时在第一行强制中断”。

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

它应该在主()方法上失效。如果你跨过几次(或按下简历),它就会到达你的测试

#3


1  

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.

这并不是一个完美的答案,但是您可以使用xdebug_start_trace()和xdebug_stop_trace()来包围任何代码块,以生成针对目标代码块的堆栈跟踪。我已经使用它来确切地看到在我的单元测试中测试其他人的代码时发生了什么。

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:

只要记住,任何失败都会导致PHPUnit的异常处理程序介入,并使堆栈跟踪看起来有点奇怪。如果出现错误,可以通过添加退出来获得干净的跟踪;叫xdebug_stop_trace之后:

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