How to get the current URL after a redirect in a Symfony2 WebTestCase? How to get the current URL after a redirect in a Symfony2 WebTestCase? symfony symfony

How to get the current URL after a redirect in a Symfony2 WebTestCase?


You can get the current URL with $client->getResponse()->headers->get('location'), and assert it ends with /login using assertRegExp().

$this->assertRegExp('/\/login$/', $client->getResponse()->headers->get('location'));


Just tried Samy Dindane solution without success (maybe something changed from 2.0)

Anyway, in 2.1, I was able to retrieve current URL in test with:

$client->getRequest()->getUri()

Then, you can use assertRegexp().


You can also do something like this (Symfony 2.3)

$client->getHistory()->current()->getUri()