简体   繁体   English

NetBeans调试不适用于phpunit测试

[英]NetBeans debug not working for phpunit tests

I followed Rafael Dohms's article to use NetBeans debugging tools for phpunit tests. 我按照Rafael Dohms的文章使用NetBeans调试工具进行phpunit测试。

The problem is when I start debugging in NetBeans and run test using command line, NetBeans switches from "waiting for connection" state to "netbeans-xdebug runnig". 问题是当我在NetBeans中开始调试并使用命令行运行测试时,NetBeans从“等待连接”状态切换到“netbeans-xdebug runnig”。 But program stops at command line after "cofiguration read from ..." and also none of debug actions(Step over, Step into etc) are active. 但是程序在“cofiguration read from ...”之后停止在命令行,并且调试操作(Step over,Step into etc)都没有激活。

I tried to disable "Stop at first line" option and also using debug file for debuging, but none of them worked. 我试图禁用“在第一行停止”选项并使用调试文件进行调试,但没有一个工作。

Did I miss something in configuration or using NetBeans tools? 我是否遗漏了配置或使用NetBeans工具的内容?

update 更新

I tried to fix the problem using NetBeans but it didn't work. 我尝试使用NetBeans解决问题,但它无法正常工作。 finally I used PhpStrom to debug the code, although I got same result, I succeed to debug normal CLI program and also tracking my phpunit test program. 最后我使用PhpStrom来调试代码,虽然我得到了相同的结果,但我成功调试了普通的CLI程序并跟踪了我的phpunit测试程序。 I realized that debugging freezes in "pear\\PHPUnit\\Util\\PHP.php" file, in the following line: 我意识到调试冻结在“pear \\ PHPUnit \\ Util \\ PHP.php”文件中,如下所示:

$stdout = stream_get_contents($pipes[1]);

I'm using Windows 7 and php-v5.3 我使用的是Windows 7和php-v5.3

Found this post when searching for the line 在搜索该行时找到此帖子

$stdout = stream_get_contents($pipes[1]);

in combination with keywords xdebug and phpunit. 结合关键字xdebug和phpunit。

I got stuck with equal symptoms, phpstorm (never tried netbeans) eventually led me to this line stalling. 我遇到了相同的症状,phpstorm(从未尝试过netbeans)最终导致我停止这一行。

During stepping to this line I noticed some mentions of 'process isolation', which made me drop the --process-isolation parameter in my xdebug call (this in itself we use to workaround a memory leak). 在踩到这一行的过程中,我注意到了一些“进程隔离”,这让我在我的xdebug调用中删除了--process-isolation参数(这本身就是我们用来解决内存泄漏的问题)。 Now the bugging line does not get called, and normal xdebug/unittest operation continiue's 现在不会调用窃听行,并且正常的xdebug / unittest操作会继续

Not claiming this to be a solution, but at least was a workable workaround for me. 没有声称这是一个解决方案,但至少对我来说是一个可行的解决方法。 Also might give some direction to actually problem/solution 也可能为实际问题/解决方案提供一些指导

You need to have installed Xdebug on Webserver, usually listening on port 9000. 您需要在Web服务器上安装Xdebug,通常在端口9000上侦听。

Check this blog post how to configure Xdebug http://bogdan-albei.blogspot.co.uk/2010/06/php-remote-debugging-with-xdebug-and.html 查看此博客文章如何配置Xdebug http://bogdan-albei.blogspot.co.uk/2010/06/php-remote-debugging-with-xdebug-and.html

From what you wrote it seems to me that Xdebug doesn't work. 根据你所写的内容,我认为Xdebug不起作用。

Make sure you have debug setting is both apache2 and cli php.ini 确保您的调试设置是apache2和cli php.ini

I add the following entry into both these files 我将以下条目添加到这两个文件中

/etc/php5/cli/php.ini /etc/php5/cli/php.ini

/etc/php5/apache2/php.ini /etc/php5/apache2/php.ini

[xdebug]
zend_extension = /usr/lib/php5/20090626/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

The problem could be using the strict mode in phpunit, eg in phpunit.xml . 问题可能是在phpunit中使用严格模式,例如在phpunit.xml

Because of this setting stopping at a breakpoint triggers a timeout. 由于此设置,在断点处停止会触发超时。 Without strict mode no timeouts are active. 没有严格模式,没有超时活动。

I had a same problem and nowhere found a correct solution but now I debug my test cases. 我有同样的问题,没有找到正确的解决方案,但现在我调试我的测试用例。 I hope this short "how to" will be helpful for you also. 我希望这篇简短的“怎么样”也对你有所帮助。

When you debugging in browser there only differents in the $_SERVER superglobals so first of all you need this. 当你在浏览器中调试时,$ _SERVER超全局只有不同的东西,所以首先你需要这个。

Just throw an Exception in your test case for examle: 只需在测试用例中抛出异常即可:

throw new Exception(json_encode($_SERVER));

If everything ok then you will see something like this in your test error message: 如果一切正常,那么您将在测试错误消息中看到类似的内容:

{"ALLUSERSPROFILE":"C:\\ProgramData","APPDATA":"C:\\User......

create a file (for example named: " phpunit-debug._SERVER.json ") and copy-paste full json line into this file. 创建一个文件(例如名为:“ phpunit-debug._SERVER.json ”)并将完整的json行复制粘贴到此文件中。

second, you have to make a "phpunit-debug.php" file with this content: 第二,你必须使用这个内容制作一个“phpunit-debug.php”文件:

$_SERVER = (array) json_decode(file_get_contents("phpunit-debug._SERVER.json")); // include your bootstrap if it's necessary... include 'c:\\xampp\\php\\phpunit'; // TADAA! your PHPUnit tricked and believe // that you called by NetBeans ;) but can // debugging with xdebug as usually

Perhaps things have changed, but I was in no way able to initiate the connection from terminal when running phpunit with Netbeans 8.1 after trying each of the previous answers here. 也许事情已经发生了变化,但是在尝试了之前的每个答案之后,在运行phpunit和Netbeans 8.1时,我无法从终端启动连接。 At best it would just say in the nb console, run... done. 充其量它只会在nb控制台中说,运行...完成。 Never any waiting for connection. 永远不要等待连接。

What did work for me was to initiate it from Netbeans. 对我有用的是从Netbeans发起它。

Here's some instructions that worked for me on Ubuntu 16.04 assuming php and netbeans are already installed and working . 假设php和netbeans已经安装并正常工作 ,这里有一些在Ubuntu 16.04上适用的指令。

  1. Install the xdebug extension 安装xdebug扩展

     sudo apt install php-xdebug 
  2. Enable it 启用它

     sudo phpenmod xdebug 
  3. Add environment variables to php.ini or /etc/php/7.0/cli/conf.d/20-xdebug.ini 将环境变量添加到php.ini/etc/php/7.0/cli/conf.d/20-xdebug.ini

     zend_extension=xdebug.so xdebug.idekey=netbeans-xdebug xdebug.remote_enable= On xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 
  4. I require phpunit in my project as a composer dev dependency, so the executable is located at vendor/bin/phpunit and this is the file to set as the "Index File" 我在我的项目中需要phpunit作为composer dev依赖项,因此可执行文件位于vendor/bin/phpunit ,这是设置为“索引文件”的文件

  5. I use a phpunit.xml configuration file to set options and test suites in my project root folder. 我使用phpunit.xml配置文件在我的项目根文件夹中设置选项和测试套件。 So you need to set that directory location as the "Working Directory" so that it picks up your bootstrap etc. 因此,您需要将该目录位置设置为“工作目录”,以便它获取引导程序等。

截图netbeans项目属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM