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

Using the Symfony2 WebTestCase, I have the following test :

$client->request('GET', '/');
$this->assertTrue($client->getResponse() instanceof RedirectResponse);

$crawler = $client->followRedirect();

I would like to test the new url, after the redirection ends with /login but I have found no way to access the new URL.


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:


Then, you can use assertRegexp().

You can also do something like this (Symfony 2.3)


You can add this row $client->getResponse()->getTargetUrl() before $client->followRedirect() to get the url where you will be redirected

Test redirect from /sample to /target (can be absolute url as well)

$crawler = $client->request('GET', '/sample');

$this->assertTrue($client->getResponse() instanceof RedirectResponse);

Need Your Help

How to set font to be DejaVu Sans Mono in vim for xp?


i have installed vim for xp ,there is a file _vimrcin C:\Vim ,i have set font in _vimrc :

Can I set the default string encoding on Ruby 1.9?

ruby-on-rails ruby utf-8 character-encoding ruby-1.9

This might sound minor, but it's been driving me nuts. Since releasing an application to production last Friday on Ruby 1.9, I've been having lots of minor exceptions related to character encoding...