调试测试sfPHPUnit Symfony1.4

时间:2015-08-24 01:05:28

标签: 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', '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中相当简单,我确定有办法做到这一点,任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

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

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

您可以查看legacy doc here

  

调试功能测试

     

有时功能测试失败。因为symfony模拟浏览器   没有任何图形界面,很难诊断出来   问题。值得庆幸的是,symfony提供了debug()方法来输出   响应标题和内容:

     

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

     

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

希望这个帮助