diff --git a/cookbook/testing/simulating_authentication.rst b/cookbook/testing/simulating_authentication.rst index f2e04acd612..e13881029e9 100644 --- a/cookbook/testing/simulating_authentication.rst +++ b/cookbook/testing/simulating_authentication.rst @@ -9,8 +9,7 @@ It could become an issue especially when ``form_login`` is used, since it requires additional requests to fill in and submit the form. One of the solutions is to configure your firewall to use ``http_basic`` in -the test environment as explained in -:doc:`/cookbook/testing/http_authentication`. +the test environment as explained in :doc:`/cookbook/testing/http_authentication`. Another way would be to create a token yourself and store it in a session. While doing this, you have to make sure that an appropriate cookie is sent with a request. The following example demonstrates this technique:: @@ -45,7 +44,9 @@ with a request. The following example demonstrates this technique:: { $session = $this->client->getContainer()->get('session'); + // the firewall context (defaults to the firewall name) $firewall = 'secured_area'; + $token = new UsernamePasswordToken('admin', null, $firewall, array('ROLE_ADMIN')); $session->set('_security_'.$firewall, serialize($token)); $session->save();