在使用PHPUnit和PhpStorm进行测试时,是否可以在本地主机上调试API请求?

在使用PHPUnit和PhpStorm进行测试时,是否可以在本地主机上调试API请求?,phpunit,phpstorm,xdebug,Phpunit,Phpstorm,Xdebug,我的配置使用PHPUnit在PhpStorm中成功地测试了本地主机API。我也可以在断点上停止,但只能在我的TestCase类中停止 我需要在测试逻辑内部设置的断点上停止,但它不会停止 测试命令: /usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 /foo/vendors/composer/phpunit/p

我的配置使用PHPUnit在PhpStorm中成功地测试了本地主机API。我也可以在断点上停止,但只能在我的TestCase类中停止

我需要在测试逻辑内部设置的断点上停止,但它不会停止

测试命令:

/usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 /foo/vendors/composer/phpunit/phpunit/phpunit --configuration /foo/_stuff/phpunit/config-api2.xml --teamcity
我的配置xml:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    bootstrap="../../foo/tests/app_test_case.php"
    colors="true"
    stopOnFailure="false"
>
    <testsuites>
        <testsuite name="foo">
            <file>../../foo.php</file>
        </testsuite>
添加到请求的路线:

?XDEBUG_SESSION_START=PHPSTORM
并在index.php中添加了cookie:

header('Cookie: XDEBUG_SESSION=PHPSTORM');
是的,你可以

这里的问题是如何为这些API调用启动调试会话

最常用的方法是将
xdebug.remote_autostart=1
添加到php.ini中,以便运行调用的解释器能够为每个php调用启动调试会话,不管是否为API


如果您对它不满意,可以将
XDEBUG\u SESSION\u START
GET参数添加到调用的HTTP请求中,但这显然需要修改代码。

更新了主帖子。它仍然没有在我的逻辑代码中的断点上停止。值得一看then.in xdebug日志,它说的是未命中的断点:
这一行表示PhpStorm正在通知xdebug它有某些断点,这并不意味着它是正确的调试会话或已到达断点。我想我欠你一些解释。您可能已经在CLI解释器的php.ini中添加了
remote\u autostart
。这是错误的,因为需要调试的是web请求,因此应该为web服务器解释器配置Xdebug。您向其发出请求的web服务器是否为本地服务器?如果是这样,请加载phpinfo(),并确认Xdebug配置正确。fck,路径映射是问题所在,其他一切正常
header('Cookie: XDEBUG_SESSION=PHPSTORM');