Symfony 功能测试在重定向后断言

标签 symfony redirect functional-testing assertions

我目前正在尝试编写功能测试,但在登录并重定向到新页面后我卡住了。
一切正常,直到最后断言。重定向工作正常,重定向后的内容页面正常,但我在最后一次断言时出错:断言 false 为真失败。我发现没有什么可以帮助我解决类似的问题。

这是代码:

class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
    $client = static::createClient(array(),
        array(
            'HTTP_HOST' => 'locahost'

        ));



    $crawler = $client->request('GET', '/login');
    echo $client->getRequest()->getUri();


    $form = $crawler->selectButton('Login')->form(array(
        '_username' => 'user',
        '_password' => 'pass',
    ),'POST');


    $client->submit($form);
    $this->assertTrue($client->getResponse()->isRedirect());
    $client->followRedirect();
    echo $client->getRequest()->getUri();

    print_r( $client->getResponse()->getContent());


    $this->assertTrue($crawler->filter('html:contains("New")')->count() > 0);
}

}

最佳答案

你必须得到 followredirect() 返回的爬虫功能:

$crawler = $client->followRedirect();

关于Symfony 功能测试在重定向后断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33753908/

相关文章:

php - 重复字段上特定于字段的错误

php - 页面是否可能知道已使用header()重定向到该页面?

asp.net - 无法为 'localhost' 生成绑定(bind)重定向。已添加具有相同 key 的项目

android - UiAutomator 测试套件(一组测试)

php - Symfony 的表单不可链接吗?

html - Silex Assets 文件

file - 使用 HTA 应用程序将 shell 应用程序输出重定向到文件

php - Symfony2 拒绝访问的功能测试

testing - Swift 中的功能测试。模拟应用程序流程

mongodb - 坚持一对多 Doctrine Mongodb