Debugging 调试测试sfPHPUnit Symfony1.4

Debugging 调试测试sfPHPUnit Symfony1.4,debugging,phpunit,symfony-1.4,functional-testing,Debugging,Phpunit,Symfony 1.4,Functional Testing,抱歉,如果这个问题太具体了,但是我必须重构一些旧的Symfony1.4代码,我不知道如何在测试中转储get请求的响应,以帮助调试一个奇怪的错误 所讨论的测试如下所示: public function testDataset () { $browser = $this->getBrowser(); $browser-> get('/search/dataset')-> with('request')->begin()-> isParameter('module', '

抱歉,如果这个问题太具体了,但是我必须重构一些旧的Symfony1.4代码,我不知道如何在测试中转储get请求的响应,以帮助调试一个奇怪的错误

所讨论的测试如下所示:

public function testDataset () {
$browser = $this->getBrowser();
$browser->
get('/search/dataset')->
with('request')->begin()->
isParameter('module', 'search')->
isParameter('action', 'dataset')->
end()->
with('response')->begin()->
isStatusCode(200)->
checkElement('body', '/Choose your dataset/')->
checkElement('#compareBy', '/High-density residental/')->
checkElement('#compareBy', '/Medium-density residential/')->
checkElement('#compareBy', '/Low-density residential/')->
checkElement('#compareBy', '/Commercial/')->
checkElement('#compareBy', '/CBD/')->
checkElement('#compareBy', '/Heavy industrial/')->
checkElement('#compareBy', '/Light industrial/')->
checkElement('#compareBy', '/Highway \/ Motorway/')->
checkElement('#compareBy', '/Arterial roads/')->
checkElement('#compareBy', '/Local roads/')->
checkElement('#compareBy', '/Open space/')->
checkElement('#dataLocation','/All New Zealand/')->
checkElement('#dataLocation','/All North Island/')->
checkElement('#dataLocation','/All South Island/')->
checkElement('#dataLocation','/Northland/')->
checkElement('#dataLocation','/Auckland/')->
checkElement('#dataLocation','/Waikato/')->
checkElement('#dataLocation','/Bay of Plenty/')->
checkElement('#dataLocation','/Taranaki/')->
checkElement('#dataLocation','/Gisborne/')->
checkElement('#dataLocation','/Hawkes Bay/')->
checkElement('#dataLocation','/Manawatu-Wanganui/')->
checkElement('#dataLocation','/Wellington/')->
checkElement('#dataLocation','/Nelson/')->
checkElement('#dataLocation','/Tasman/')->
checkElement('#dataLocation','/Marlborough/')->
checkElement('#dataLocation','/West Coast/')->
checkElement('#dataLocation','/Canterbury/')->
checkElement('#dataLocation','/Otago/')->
checkElement('#dataLocation','/Southland/')->
checkElement('#waterTypes','/All stormwater/')->
checkElement('#waterTypes','/Untreated stormwater/')->
checkElement('#waterTypes','/Treated stormwater/')->
checkElement('#waterTypes','/Urban streams/')->
checkElement('#waterTypes','/All water types/')->
checkElement('#flowType','/Storm event/')->
checkElement('#flowType','/Baseflow/')->
end();
}
其失败之处在于:

functional_frontend_searchActionsTest::testDataset
response selector "#compareBy" matches regex "/High-density residental/"
Failed asserting that false is true.
页面加载良好,但我不知道如何在测试中实际转储页面响应主体,以调查测试所看到的内容。 我试过$browser->getContent(),$browser->getResponse(),$browser->getBody()


这在phpunit/Symfony2中非常简单,我确信有办法做到这一点,有人能帮忙吗?

您可以在
sfWebResponse
对象上使用
debug
方法。例如:

$browser->with('response')->debug();
您可以在以下位置签入:

调试功能测试

有时功能测试失败。正如symfony模拟浏览器一样 如果没有任何图形界面,就很难诊断故障 问题谢天谢地,symfony提供了输出的
debug()
方法 响应标题和内容:

$browser->with('response')->debug()

debug()方法可以插入响应测试程序块中的任何位置 并将停止脚本执行。


希望这对你有所帮助

谢谢你,那太完美了。我还发现您可以使用“print_r($browser->getResponse()->getContent());die;”来转储响应。