Xdebug断点始终有效,除非使用@runTestsInSeparateProcesses? [英] Xdebug breakpoints always work except when using @runTestsInSeparateProcesses?

查看:70
本文介绍了Xdebug断点始终有效,除非使用@runTestsInSeparateProcesses?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于让Xdebug(包括断点和越过"功能)可以进行单元测试,功能测试以及在浏览器中浏览.

I finally got Xdebug working (including with breakpoints and the ability to "step over") for unit tests, feature tests, and for poking around in the browser.

但是,每当我使用 @runTestsInSeparateProcesses 由于此原因,Netbeans断点不再起作用.

However, whenever I use @runTestsInSeparateProcesses because of this reason, Netbeans breakpoints no longer work.

如何在使用@runTestsInSeparateProcesses的测试中使用Xdebug断点?

How can I use Xdebug breakpoints on tests that use @runTestsInSeparateProcesses?

我在Windows 10版本1607内部版本14393.0上使用Netbeans 8.2. PHPUnit 5.7.21.

I'm using Netbeans 8.2 on Windows 10 Version 1607 Build 14393.0. PHPUnit 5.7.21.

我正在运行Laravel 5.4 Homestead(即Vagrant 1.9.5),因此这意味着我的服务器是Ubuntu 16.04.2 LTS(GNU/Linux 4.4.0-66-通用x86_64).

I'm running Laravel 5.4 Homestead (which is Vagrant 1.9.5), so that means my server is Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-66-generic x86_64).

推荐答案

您需要将xdebug配置添加到php.ini中,以便如果phpunit再次调用php解释器(@runTestsInSeparateProcesses的b/c)来在加载的单独进程中运行测试,并自动将xdebug激活(远程调试设置等),而无需将任何其他参数传递给可执行文件.

You need to add the xdebug configuration to your php.ini so that if phpunit invokes the php-interpreter another time (b/c of @runTestsInSeparateProcesses) to run the test in a separate process is loaded and has xdebug activate automatically (remote debug settings etc.) w/o any further parameters passed to the executable.

如果您已经这样做(问题可能并非如此),请确保您的IDE接受的不止一个xdebug连接(xdebug连接限制或类似限制).这是必要的,因为新的PHP进程将启动一个新的xdebug远程会话,该会话需要额外的连接.如果未实现该连接,则xdebug将等待,例如连接限制为一(1),您将看到PHP挂起.

If you have done this already (which might not be the case from your question), ensure that your IDE is accepting more than a single xdebug connection (xdebug connection limit or similar). This is necessary as a new PHP process will start a new xdebug remote session which needs an additional connection. If that connection is not fulfilled, xdebug will wait so with a connection limit of one (1) for example, you will see that PHP hangs.

此方法的缺点是xdebug将始终加载,这将添加ca.在CLI中执行的PHP的性能提高了10%.

The drawback with this approach is that xdebug will be loaded always which will add ca. 10% performance onto PHP executed within the CLI.

在开发箱上,您可以自己创建一些脚本,您可以运行这些脚本来打开和关闭已安装的PHP二进制文件的xdebug默认配置.

As far as this is on a development box, you can create yourself some script you can run to switch xdebug default configuration on and off for the installed PHP binary.

Composer不受此影响,因为它会在禁用xdebug的情况下重新启动,但是大多数其他PHP cli工具都不会这样做(并且也许不需要它,因为存在如此多的性能,缺点是可以忽略不计.对于执行大量对象创建等工作的PHP脚本而言,这最重要.

Composer is not affected by this as it will re-launch itself with xdebug disabled, but most other PHP cli tools don't do this (and perhaps don't need it as there is so much performance available and the drawback can be neglected. it's mostly important for PHP scripts that do a lot of object creation and such).

因此,设置您的php.ini并启用xdebug.一个好的IDE会显示它自动添加的设置(PHP cli -d选项),只需将它们添加到您的php.ini中,您就可以在该测试场景中正常工作.

So, setup your php.ini and enable xdebug. A good IDE shows the settings it automatically adds (PHP cli -d options), just add these to your php.ini and you should be fine for that testing scenario.

当它开始工作时,请考虑一下如何立即禁用设置(sed对此非常方便,尤其是在GNU系统上的-i [就地编辑]时,Stackoverflow应该使您对基础知识感到满意.在这里,对于Windows,我无法说出什么效果很好,以防万一.)

When you get it to work, think about how to disable settings on the fly (sed is handy for that, especially with -i [edit In place] on GNU systems, Stackoverflow should keep you happy with the basics here, for Windows I can't say what is working well, in case you wonder).

补充说明:我不能专门针对Netbeans讲,因为我不使用它,但是对于Phpstorm,这是完全相同的(我以为是),因为它在为测试调用时将xdebug添加到PHP配置中(调试,覆盖率)以及导致其他PHP脚本的子进程无法调试,除非我将添加的xdebug配置放入php.ini.

Additional note: I can't specifically say for Netbeans as I don't use it, but with Phpstorm this is quite the same (I assume in good faith) as it adds xdebug to the PHP configuration when invoked for tests (debug, coverage), and spawned sub-process which lead to other PHP scripts can't be debugged unless I put that added xdebug configuration into the php.ini.

这篇关于Xdebug断点始终有效,除非使用@runTestsInSeparateProcesses?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆