Authentication in functional tests in Symfony 2.1

后端 未结 5 743
梦谈多话
梦谈多话 2020-12-13 05:15

I am currently in the process of migrating a 2.0.* project to the current 2.1 beta of Symfony.

In my functional tests i currently have this code to create a client w

5条回答
  •  孤街浪徒
    2020-12-13 05:47

    Proper way to authenticate user is:

    $firewallName = 'your-firewall-name';
    $container = self::$kernel->getContainer()
    $token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles());
    $container->get('security.context')->setToken($token);
    

    and firewall authentication:

    $session = $container->get('session');
    $session->set('_security_'.$firewallName, serialize($token));
    $session->save();
    

提交回复
热议问题