Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Functional Testing $crawler Not Working

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

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());

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"

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

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

like image 570
Matt Avatar asked Dec 13 '22 04:12

Matt


1 Answers

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);
like image 199
Matt Avatar answered Dec 17 '22 07:12

Matt