【问题标题】:Symfony2: functional test of record edit failsSymfony2:记录编辑功能测试失败
【发布时间】:2013-02-26 22:32:21
【问题描述】:

我正处于功能测试学习曲线的陡峭部分。在更改机构状态(是->否、否->是)的简单表单上,记录编辑失败。测试代码为:

$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。我已经构建了一个可以正确添加代理的测试,因此我知道我并没有完全偏离轨道。 (我还想有更简单的方法来计算“是”出现在表格中的次数。)

谢谢。

【问题讨论】:

  • $client->getResponse()->getContent()$crawler = $client->submit($form); 之后是什么样子您应该使用$this->assertTrue($client->getResponse()->isSuccessful()); 检查每次 POST/GET 后响应是否成功,以确保您的测试配置没有任何问题,或在请求期间未引发其他异常。
  • @james_t: $client->getResponse()->getContent() 在 Windows shell 中似乎为空(仅 .)。 $this->assertTrue($client->getResponse()->isSuccessful()) 断言不会失败。
  • 更正:...getContent() 在使用var_dump() 时返回预期页面的html。
  • 但是错了:添加代码将内容写入文件后,我可以看到整个内容,内容是编辑页面,而不是成功编辑后应该返回的页面。

标签: symfony phpunit functional-testing


【解决方案1】:

答案:修复编辑动作的路由!现在测试通过了。

【讨论】:

    猜你喜欢
    • 2014-04-30
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多