【发布时间】:2018-01-30 23:39:53
【问题描述】:
在 PhpStorm 中调试测试类(PHPUnit_Framework_TestCase 的子类)时,它会在此类中设置的断点处停止,但不会在请求指向的控制器 (Symfony) 中停止。
//test class - here debugger stops
class FooControllerTest extends \PHPUnit_Framework_TestCase
{
public function testPOST()
{
$response = $this->client->post('/api/foo', [
'body' => json_encode($data)
]);
.
//controller - here debugger not stopping
/**
* @Route("/api/foo")
* @Method("POST")
*/
public function newAction(Request $request)
{
//...
return new Response($json, 201, array(
'Content-Type' => 'application/json'
));
请求肯定会进入这个控制器,因为我可以在那里更改 http 代码,并且此更改在 client->post( 行之后的测试类中是可读的
如何在测试时调试控制器?
【问题讨论】:
-
很可能它是作为附加/单独的请求完成的,并且没有传递“调试我”标志。 IDE 设置也可以处理最多 1 个同时调试会话(默认设置)。对于第一点——也许配置 xdebug 来调试任何传入的请求而没有任何标志 (
xdebug.remote_autostart=1)。显然,在其他情况下并不理想。或者向此类请求添加 xdebug cookie 或 GET 参数。也可以尝试将xdebug_break();放在实际代码中——应该可以。 -
第二点——在 IDE 设置中增加该数字(提示:使用设置/首选项屏幕中的搜索框,将“xdebug”作为关键字)
-
@LazyOne 谢谢,添加了 GET 参数及其工作。在同时会话数量增加后使用
xdebug.remote_autostart=1和xdebug_break();的解决方案不起作用。我将其添加为答案,如果您关心分数,您可以将我的答案复制到您的(然后我将删除我的)
标签: symfony debugging phpunit phpstorm guzzle