0

I'd like to run functional tests on a section of my website which requires authentication. I found a solution for Symfony 2.x here. However, this does not work for Symfony3 as this line is now deprecated:

self::$kernel->getContainer()->get('security.context')->setToken($token);

My question is, how do I go around this and make it work with Symfony3? Thank you.

Community
  • 1
  • 1
Mike
  • 6,854
  • 17
  • 53
  • 68

1 Answers1

1

In Symfony 3, the SecurityContext was split into the TokenStorage and the AuthorizationChecker. Thus, you need to use the security.token_storage service:

self::$kernel->getContainer()->get('security.token_storage')->setToken($token);

However, a simpler approach would be to switch to HTTP Basic auth in your tests and configure the logged in user as described in http://symfony.com/doc/current/cookbook/testing/http_authentication.html.

xabbuh
  • 5,801
  • 16
  • 18