bla*_*e24 51 php phpunit xdebug command-line-interface
我试过运行以下CLI命令:
phpunit -d xdebug.profiler_enable=on XYZTestCase.php
Run Code Online (Sandbox Code Playgroud)
但它只是正常运行.谁能指出我正确的方向?谢谢!
这是XDebug设置:
xdebug
xdebug support => enabled
Version => 2.1.2
Supported protocols => Revision
DBGp - Common DeBuGger Protocol => $Revision: 1.145 $
Directive => Local Value => Master Value
xdebug.auto_trace => Off => Off
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.idekey => Nam => no value
xdebug.manual_url => http://www.php.net => http://www.php.net
xdebug.max_nesting_level => 100 => 100
xdebug.overload_var_dump => On => On
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_output_dir => c:/wamp/tmp => c:/wamp/tmp
xdebug.profiler_output_name => cachegrind.out.%t.%p => cachegrind.out.%t.%p
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.scream => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => \ => \
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3
Run Code Online (Sandbox Code Playgroud)
edo*_*ian 47
该xdebug.profiler_enable设置不能在运行时更改,而只能在脚本开头更改.
运行phpunit -d foo=bar只会导致phpunit调用ini_set("foo", "bar");,这不起作用,因为值不能在运行时更改.
启用Xdebug的分析器,该分析器在配置文件输出目录中创建文件.KCacheGrind可以读取这些文件以可视化您的数据.无法使用ini_set()在脚本中设置此设置.如果要有选择地启用探查器,请将xdebug.profiler_enable_trigger设置为1而不是使用此设置.
php -d xdebug.profiler_enable=on /usr/bin/phpunit XYZTestCase.php
Run Code Online (Sandbox Code Playgroud)
通过将设置直接应用于PHP运行时而不是phpunit,它将在脚本启动之前设置并且应该可以正常工作.
花了很多年才试图让它发挥作用.认为这可能会改变我的生活!
我最初试图在流浪盒内做这个(即运行phpunit)但是意识到在流浪盒外面运行它更容易(并且性能更快).
首先我brew install php55 php55-xdebug在mac上使用自制软件(但你的配置可能不同,它应该仍然有用).我的网站是一个symfony2项目.
我试图遵循这个:phpunit vagrant xdebug让它在一个流浪盒内工作(几乎到了那里,但有一些问题).
这些设置对我有用(从流浪盒中运行站点,但在流浪盒外面运行phpunit):
#xdebug.ini (parent machine, not inside vagrant box).
[xdebug]
zend_extension="/usr/local/Cellar/php55-xdebug/2.2.6/xdebug.so" #this will be different on your machine and will probably already be set
xdebug.max_nesting_level = 250
xdebug.default_enable = 1
xdebug.idekey = "PHPSTORM" #seems to work without this too
xdebug.remote_enable = 1
Run Code Online (Sandbox Code Playgroud)
然后在命令行运行它(这里我使用的是phpunit的下载而不是链接到/ usr/local/bin的那个(这似乎不起作用))
XDEBUG_CONFIG="idekey=PHPSTORM" bin/phpunit -c app
Run Code Online (Sandbox Code Playgroud)
或者您可以创建一个名为phpunit-debug的文件(用于存储XDEBUG_CONFIG环境变量),如下所示:phpunit xdebug
您是否尝试过:
重启你的服务器
通过添加-d xdebug.idekey=blacktie调用您的脚本
phpunit -d xdebug.profiler_enable=on -d xdebug.idekey=blacktie XYZTestCase.php
希望有所帮助。
您可以通过预先设置环境变量从命令行运行 Xdebug,例如:
export XDEBUG_CONFIG="idekey=YOUR_IDE_KEY remote_host=localhost remote_enable=1"
这对我有用。
有关Xdebug 文档的更多信息。
在使用 VS code 调试器(使用 WSL)时,我在终端中唯一需要做的就是执行以下命令:
export XDEBUG_CONFIG="idekey=VSCODE"
Run Code Online (Sandbox Code Playgroud)
之后我只需像往常一样运行 phpunit 命令。即phpunit ./tests/调试器将停止在我设置的第一个断点处。
如果调试器在无法访问的代码处暂停,您可能需要在调试器窗格中的断点下切换“Everything”。
我从https://tighten.co/blog/configure-vscode-to-debug-phpunit-tests-with-xdebug获取此信息
:: 编辑 ::
虽然上述内容在我的本地网络服务器上有效。今天,当我尝试将我的项目移植到 docker 时,我遇到了这个问题。
事实证明,它不适用于此设置:
xdebug.remote_connect_back=1
Run Code Online (Sandbox Code Playgroud)
但你需要这样设置:
xdebug.remote_host=172.17.0.1
xdebug.remote_connect_back=0
Run Code Online (Sandbox Code Playgroud)
注意:我使用 172.17.0.1 从 docker 容器内部引用我的主机,因为我使用的是 Linux,但如果你使用的是 Mac,则可能更好使用:
xdebug.remote_host=docker.for.mac.host.internal
xdebug.remote_connect_back=0
Run Code Online (Sandbox Code Playgroud)
或在 Windows 上:
xdebug.remote_host=host.docker.internal
xdebug.remote_connect_back=0
Run Code Online (Sandbox Code Playgroud)
有了 docker,我似乎也不需要再做export XDEBUG_CONFIG="idekey=VSCODE"任何事情了。
设置的正确名称xdebug.profiler_enable带有下划线。将命令更改为:
phpunit -d xdebug.profiler_enable=on XYZTestCase.php
Run Code Online (Sandbox Code Playgroud)