简体   繁体   English

通过PhpStorm运行PHPUnit之前在Docker容器中禁用Xdebug

[英]Disable Xdebug in docker container before running PHPUnit via PhpStorm

I configured PhpStorm according to this tutorial: PHPUnit for PhpStorm 我根据本教程配置了PhpStorm: PHPUnit for PhpStorm

I can run my PHPUnit test successfully, so this is working. 我可以成功运行PHPUnit测试,因此可以正常工作。

The problem is, in my docker container I have enabled Xdebug which I need sometimes. 问题是,在我的Docker容器中,我启用了Xdebug,有时我需要。 Normally, I docker exec into the container and run the tests there. 通常,我将docker exec放入容器并在其中运行测试。 Xdebug slows down the tests heavily, so I do phpdismod -s cli xdebug before I run my tests. Xdebug大大降低了测试速度,因此在运行测试之前,我先进行了phpdismod -s cli xdebug Then the tests run 100x faster! 然后测试运行速度提高了100倍!

Now I want to achieve the same behaviour when I run the tests through PhpStorm. 现在,我想通过PhpStorm运行测试时实现相同的行为。 PhpStorm brings up an own docker container where it runs the tests. PhpStorm会启动一个自己的docker容器,用于运行测试。 I don't know how I can tell PhpStorm to run phpdismod -s cli xdebug before starting PHPUnit. 我不知道如何在启动PHPUnit之前告诉PhpStorm运行phpdismod -s cli xdebug Is there a way of doing that? 有办法吗?

According to the link you mentioned, there is a way to set image name like shlink_shlink_php:latest for example. 根据您提到的链接,有一种方法可以设置图像名称,例如shlink_shlink_php:latest

What you need to do is to add entrypoint.sh in your own image and based on envrionment variable you may enable or disable the debugging mode for example: 您需要做的是在自己的映像中添加entrypoint.sh ,并根据环境变量可以启用或禁用调试模式,例如:

export DEBUG="${DEBUG:-on}"
if [ "$DEBUG" == "off" ]; then
  phpdismod -s cli xdebug
fi

So by default the debug value is on which means to leave the xdebug mode active. 因此,默认情况下,调试值on ,这意味着将xdebug模式保持活动状态。 however if you passed an environment value called DEBUG with value off then it will disable xdebug. 但是,如果您传递了一个名为DEBUG的环境值且该值处于off则它将禁用xdebug。

You can pass environment variables as explained in here . 您可以按照此处的说明传递环境变量。

Alternatively, you may check the following options which mentioned in here for example try to pass -dxdebug.remote_enable=0 through php additional options from PHPStorm (I am not sure if preventing connection to remote interpreter will be the same as disabling the debugger as i am not expert in this part but you may check it too ) 或者,您可以检查此处提到的以下选项,例如尝试通过-dxdebug.remote_enable=0通过php其他选项传递-dxdebug.remote_enable=0 (我不确定禁止与远程解释器的连接是否与禁用调试器相同,因为我不是这部分的专家,但您也可以检查它)

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

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