我正处于功能测试学习曲线的陡峭部分。在更改代理商状态的简单表单上(是 - >否,否 - >是),记录编辑失败。测试代码是:
$crawler = $client->request('GET', '/agency/manage');
//read agency table
$nodeValues = $crawler->filter('td')->each(function ($node, $i) {
return $node->nodeValue;
});
//$initial = number of Active=Yes agencies
$initial = 0;
foreach ($nodeValues as $node) {
if ($node == 'Yes') {
$initial ++;
}
}
//edit agency to Active=No
$crawler = $client->request('GET', '/agency/1/edit');
$form = $crawler->selectButton('Edit')->form();
$form['agency[active]'] = 'No';
$crawler = $client->submit($form);
$crawler = $client->request('GET', '/agency/manage');
$nodeValues = $crawler->filter('td')->each(function ($node, $i) {
return $node->nodeValue;
});
//$final = number of Active=Yes agencies
$final = 0;
foreach ($nodeValues as $node) {
if ($node == 'Yes') {
$final ++;
}
}
$this->assertTrue($initial > $final);
对于我的测试用例,初始值和最终值均为2.我已经构建了一个正确添加代理的测试,因此我知道我并非完全偏离轨道。 (我还想象有更简单的方法来计算表中出现的次数。)
感谢。
答案 0 :(得分:0)
答案:修复编辑动作的路由!现在测试通过了。