Symfony测试得到表单错误

时间:2017-03-07 02:30:28

标签: phpunit symfony

如果我有类似的功能测试:

public function testCreate()
{

    $client = $this->makeClient();
    $crawler = $client->request('POST', "/post/new");

    $form = $crawler->selectButton("Create Post")->form();
    $values = $form->getPhpValues();

    $values['post']['title'] = 'test';
    $values['post']['content'] = null; // Should fail because it isn't a string.


    $crawler = $client->request($form->getMethod(), $form->getUri(), $values,
        $form->getPhpFiles());
    assertEquals() // What goes here?
}

如何使用crawler获取表单错误并进行比较?

1 个答案:

答案 0 :(得分:1)

我为您看到两种可能的解决方案:

  1. 使用抓取工具检查呈现的HTML代码中实际呈现的表单错误。
  2. 使用分析器并访问表单数据收集器:http://symfony.com/doc/current/testing/profiling.html