4

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?

Matt
  • 5,478
  • 9
  • 56
  • 95
  • It is normal to have funcional testing accessing http://localhost as it doesn't a full http request, but it simulates one. Try looking in your app/logs to identify the error. – Stefano Sala Mar 12 '12 at 09:14
  • I know what the error is. It is accessing localhost, which is setup as a different virtual server than my application so the page it is requesting is just a 404. I want to know if I can instead change the domain crawler uses or somehow find a workaround. – Matt Mar 12 '12 at 19:45

1 Answers1

14

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);
Lorenzo Polidori
  • 10,332
  • 10
  • 51
  • 60
Matt
  • 5,478
  • 9
  • 56
  • 95