php - Symfony 2 functional test: authenticate user of own User class -


as described in answer of how use authenticated user in symfony2 functional test? there simple solution symfony\component\security\core\user\user.

but have different user class (some necessary additional fields) , want authenticate user it.

how can setup providders it?

this tricky issue discussed here: https://github.com/symfony/symfony/issues/5228 though 2.1, still happen me using 2.2.

here how test authentication:

// create new client browse application $client = static::createclient(); $client->getcookiejar()->set(new cookie(session_name(), true));  // dummy call bypass hasprevioussession check $crawler = $client->request('get', '/');  $em = $client->getcontainer()->get('doctrine')->getentitymanager(); $user = $em->getrepository('myownbundle:user')->findonebyusername('username');  $token = new usernamepasswordtoken($user, $user->getpassword(), 'main_firewall', $user->getroles()); self::$kernel->getcontainer()->get('security.context')->settoken($token);  $session = $client->getcontainer()->get('session'); $session->set('_security_' . 'main_firewall', serialize($token)); $session->save();  $crawler = $client->request('get', '/login/required/page/');  $this->asserttrue(200 === $client->getresponse()->getstatuscode());  // perform tests in /login/required/page here.. 

oh, , use statements:

use symfony\component\security\core\authentication\token\usernamepasswordtoken; use symfony\bundle\frameworkbundle\client; use symfony\component\browserkit\cookie; 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -