66

我尝试运行以下 CLI 命令:

phpunit -d xdebug.profiler_enable=on XYZTestCase.php

但它只是正常运行。谁能指出我正确的方向?谢谢!

这是 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
4

9 回答 9

55

xdebug.profiler_enable设置不能在运行时更改,只能在脚本开始时更改。

运行phpunit -d foo=bar只会导致 phpunit 调用ini_set("foo", "bar");,这不起作用,因为该值在运行时无法更改。

看:xdebug.profiler_enable

启用 Xdebug 的分析器,它在配置文件输出目录中创建文件。KCacheGrind 可以读取这些文件以可视化您的数据。无法使用 ini_set() 在脚本中设置此设置。如果您想选择性地启用分析器,请将 xdebug.profiler_enable_trigger 设置为 1 而不是使用此设置。

解决方案:

php -d xdebug.profiler_enable=on /usr/bin/phpunit XYZTestCase.php

通过将设置直接应用于 PHP 运行时而不是 phpunit,它将在脚本启动之前设置并且应该可以工作。

于 2012-08-27T12:09:21.547 回答
14

花了很长时间试图让它发挥作用。认为这可能会改变我的生活!

我最初试图在 vagrant box 内执行此操作(即运行 phpunit),但意识到在 vagrant box 外运行它更容易(并且性能更快)。

首先,我brew install php55 php55-xdebug在 Mac 上使用自制软件(但您的配置可能不同,它仍然可以工作)。我的网站是一个 symfony2 项目。

我试图遵循这个:phpunit vagrant xdebug让它从一个流浪者盒子里工作(几乎到了那里,但有一些问题)。

这些设置对我有用(从 vagrant box 运行站点,但 phpunit 在 vagrant box 外):

#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

然后在命令行运行它(这里我使用的是 phpunit 的下载,而不是 /usr/local/bin 中链接的那个(这似乎不起作用))

XDEBUG_CONFIG="idekey=PHPSTORM" bin/phpunit -c app

或者您可以创建一个名为 phpunit-debug 的文件(用于存储 XDEBUG_CONFIG 环境变量),如下所述:phpunit xdebug

于 2014-12-03T17:39:12.300 回答
7

您是否尝试过:

  1. 将您的xdebug.idekey在您的 php.ini 中设置为您想要的任何内容(例如:blacktie)
  2. 重启你的服务器

  3. 通过添加-d xdebug.idekey=blacktie调用您的脚本

    phpunit -d xdebug.profiler_enable=on -d xdebug.idekey=blacktie XYZTestCase.php

希望有所帮助。

于 2012-08-27T07:54:34.627 回答
4

设置的正确名称xdebug.profiler_enable带有下划线。将您的命令更改为:

phpunit -d xdebug.profiler_enable=on XYZTestCase.php
于 2012-08-25T21:17:24.830 回答
4

您可以通过预先设置环境变量从命令行运行 Xdebug,例如:

export XDEBUG_CONFIG="idekey=YOUR_IDE_KEY remote_host=localhost remote_enable=1"

这对我有用。

有关Xdebug 文档的更多信息。

于 2016-08-22T15:11:32.637 回答
3

在使用 VS 代码调试器(使用 WSL)时,我在终端中唯一需要做的就是执行以下命令:

export XDEBUG_CONFIG="idekey=VSCODE"

之后我像往常一样简单地运行我的 phpunit 命令。即phpunit ./tests/调试器将在我设置的第一个断点处停止。

如果调试器在无法访问的代码上暂停,您可能需要在“断点”下的调试器窗格中切换“一切”。

我从https://tighten.co/blog/configure-vscode-to-debug-phpunit-tests-with-xdebug得到了这个信息

:: 编辑 ::

虽然上述内容适用于我的本地网络服务器。今天,当我试图将我的项目移植到 docker 时,我对此有所了解。

事实证明它不适用于此设置:

xdebug.remote_connect_back=1

但是您需要设置它:

xdebug.remote_host=172.17.0.1
xdebug.remote_connect_back=0

注意:我使用 172.17.0.1 从 docker 容器内引用我的主机,因为我在 linux 上,但如果你在 mac 上,最好使用:

xdebug.remote_host=docker.for.mac.host.internal
xdebug.remote_connect_back=0

或在窗户上:

xdebug.remote_host=host.docker.internal
xdebug.remote_connect_back=0

使用 docker 似乎我也不需要export XDEBUG_CONFIG="idekey=VSCODE"再做任何事情了。

于 2019-10-03T12:38:49.910 回答
0

带有 phpStorm 的 Windows 上

在命令行中输入:

set XDEBUG_CONFIG="idekey=PHPSTORM"

这将添加一个 phpStorm 将寻找的环境变量。

于 2019-06-06T23:52:34.897 回答
0

假设当被 cookie/post/get 变量触发时,您已经在编辑器/独立调试器中运行了 Xdebug,添加一个 shell 脚本来执行相同的触发,因此您无需记住:

创建~/bin/php-cli-debug.sh

#!/bin/bash
phpfile="$1"
idekey=YOUR_IDE_KEY
shift 1
php -d'xdebug.remote_enable=1' -d'xdebug.remote_autostart=1' -d'xdebug.idekey='"$idekey" -f "$phpfile" -- "$@"

然后在 CLI 上调试东西,使用类似的东西:

$ php-cli-debug.sh "$(which phpunit)" --bootstrap tests/bootstrap.php tests/FooBarTest | less -S

确保您.bashrc已添加~/bin到您的$PATH.

于 2017-09-06T06:12:39.380 回答
0

首先,我的环境:

  • WampServer 版本 3.1.3 64 位
  • 阿帕奇 2.4.33 - PHP 7.1.16
  • MySQL 5.7.21
  • MariaDB 10.2.14

php.ini:

[xdebug]
zend_extension ="c:/wamp64/bin/php/php7.1.16/zend_ext/php_xdebug-2.6.0-7.1-vc14-x86_64.dll"

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/wamp64/tmp"
xdebug.show_local_vars=0
xdebug.idekey = "PHPSTORM" #seems to work without this too

phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="bootstrap/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>

我在 phpstorm 上做了一个测试运行配置,如下所示: 点击红圈内的按钮 配置面板

进行运行配置后,当我单击 PHPSTORM 中的调试按钮时,将运行以下命令。

C:\wamp64\bin\php\php7.1.16\php.exe
-dzend_extension=C:\wamp64\bin\php\php7.1.16\zend_ext\php_xdebug-2.6.0-7.1-vc14-x86_64.dll
-dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 C:/wamp64/www/<PROJECT_FOLDER>/vendor/phpunit/phpunit/phpunit --bootstrap C:\wamp64\www\<PROJECT_FOLDER>\vendor\autoload.php --configuration C:\wamp64\www\<PROJECT_FOLDER>\phpunit.xml --teamcity

注意--teamcity. 我不知道 :) 还要注意反斜杠和正斜杠。

我希望这对每个人都有帮助。

于 2018-05-08T12:17:36.657 回答