Symfony2功能测试$ crawler无法正常工作 [英] Symfony2 Functional Testing $crawler Not Working

查看:82
本文介绍了Symfony2功能测试$ crawler无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现Symfony2中的功能测试总是尝试将页面请求为"http://localhost"

I have found that the functional tests in Symfony2 always try to request pages as "http://localhost"

我的环境已设置了虚拟主机,因此我的应用程序位于"http://symfony.dev"

My environment is setup with virtual hosts so I have my application at "http://symfony.dev"

经过一些测试,我发现如果我运行:

After some testing I have found that if I run:

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

我将获得所需的页面,但是如果我var_dump $ crawler我可以看到,它请求的不是"http://symfony.dev/page"这样的页面,而是"http://localhost/page"

I will get the page I want, but if I var_dump the $crawler I can see that rather than requesting a page like "http://symfony.dev/page" it requested "http://localhost/page"

那给出了404,所以我无法测试表单等等.

That gives a 404 so I am unable to test forms and so on.

总有没有设置基本URL来使其正常工作?我应该改用硒之类的东西吗?

Is there anyway to set the base URL to get this to work? Should I instead use something different like Selenium?

推荐答案

我发现我可以将域传递给客户端.我将使用此功能创建一个基本的WebTestCase,以便我的测试正常进行.

I found that I can pass the domain in to the Client. I will just make a base WebTestCase with this functionality so my tests work.

$client = static::createClient(array(), array('HTTP_HOST' => 'symfony.dev'));
$client->followRedirects(true);

这篇关于Symfony2功能测试$ crawler无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆