How to Simulate Authentication with a Token in a Functional Test

Authenticating requests in functional tests might slow down the suite.
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
How to Simulate HTTP Authentication in a Functional Test.
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: