Save session cookie in SessionHelper after authentication

According to this:
http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html
and this:
https://github.com/bamarni/symfony-standard/commit/317ce94dd7db092e24ac5ebf96e5eefb79c37497#commitcomment-2953995

we have to "create the cookie AFTER the session is saved". Without that the authentication does not work for me.