如何在主机上访问xdebug会话以进行在docker容器内运行的单元测试?

时间:2016-02-11 11:55:12

标签: php docker phpunit xdebug hhvm

我有一个使用hhvm在docker容器内运行的php应用程序。

我的IDE是在我的localhost上运行的phpstorm,我设置了xdebug。

int i; int.TryParse("0", out i);的提升部分如下:

/etc/hhvm/php.ini

在我的nginx conf中,我必须添加指定服务器名称以匹配我的反向代理。反向代理在我的localhost上运行,并将容器的IP(例如; xdebug hhvm.debug.server_error_message = true xdebug.enable=1 xdebug.remote_enable=1 xdebug.idekey="PHPSTORM" xdebug.remote_port = 9999 xdebug.remote_autostart=1 xdebug.remote_connect_back=1 xdebug.remote_handler=dbgp xdebug.remote_log="/var/log/xdebug/xdebug.log" )映射到人类可读的127.0.0.1:8080

nginx conf条目如下所示:

http://my_app.local

当我向服务器发出请求时,这会让我得到一个有效的xdebug连接。

然而,一旦我使用phpunit从docker容器内部运行单元和功能测试,我也想要一个xdebug会话:

cat nginx/conf.d/my_app.conf 
server {
listen 80 default_server;
server_name my_app.local;

root /var/www/my_app/web;
index index.php index.html index.htm;

include hhvm.conf;

error_log  /var/log/nginx/sandbox/error.log;
access_log  /var/log/nginx/sandbox/access.log  main;

location /status {
  return 200;
  access_log off;
}

location ~/(assets|img|html|src|docs|bower_components|dist)/ {
   try_files $uri =404;
}

location / {
    try_files $uri /app.php$is_args$args;
}

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt  { log_not_found off; access_log off; }
}

我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:1)

您可以使用此方法:

PHP_IDE_CONFIG="serverName=my_app.local" "XDEBUG_CONFIG="remote_enable=1 remote_host=YOUR_REMOTE_IP idekey=PHPSTORM" ./vendor/bin/phpunit -c tests/phpunit-no-coverage.xml

服务器名称必须添加到phpstorm Langauge&框架> PHP>已配置服务器配置并且必须确保定义了正确的路径映射。

答案 1 :(得分:0)

xdebug.remote_connect_back=1需要$_SERVER['REMOTE_ADDR']。尝试明确定义它:

le-docker-container:/var/www/my-app# REMOTE_ADDR="10.0.0.1" ./vendor/bin/phpunit -c tests/phpunit-no-coverage.xml

或更改xdebug配置以改为使用xdebug.remote_host

相关问题