Matt
Matt

Reputation: 5567

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?

Upvotes: 4

Views: 5268

Answers (1)

Matt
Matt

Reputation: 5567

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

Upvotes: 14

Related Questions