Reputation: 153
who knows how to create a symfony2.1.x session for phpunit tests ?
i found this, but it`s not working:
$account = $this->em->getRepository('BaseBundle:Account');
$user = $account->findOneById('835d278dfb30');
$container = $this->client->getContainer();
$token = new UsernamePasswordToken($user, null, array('IS_AUTHENTICATED_FULLY', 'IS_AUTHENTICATED_ANONYMOUS'));
$this->client->getContainer()->get('security.context')->setToken($token);
$session = $this->client->getContainer()->get('session');
$session->set('_security_secured_area', serialize($token));
$session->save();
after this i tried to make a request to the account url, which is protected through symfony´s security area and it should me not redirect to the login page :(
Please help me, i tried a lot of stuff out there but nothing works.
Upvotes: 1
Views: 1869
Reputation: 106
you can use Symfony session mock objects.
Link to documentation: http://symfony.com/doc/current/components/http_foundation/session_testing.html
Upvotes: 1