title: phpunit session symfony2
body: <p>who knows how to create a symfony2.1.x session for phpunit tests ?</p>
  
  <p>i found this, but it`s not working:</p>
  
  <pre><code>$account = $this-&gt;em-&gt;getRepository('BaseBundle:Account');
  $user = $account-&gt;findOneById('835d278dfb30');        
  $container = $this-&gt;client-&gt;getContainer();
  
  $token = new UsernamePasswordToken($user, null, array('IS_AUTHENTICATED_FULLY', 'IS_AUTHENTICATED_ANONYMOUS'));
  $this-&gt;client-&gt;getContainer()-&gt;get('security.context')-&gt;setToken($token);
  $session = $this-&gt;client-&gt;getContainer()-&gt;get('session');
  $session-&gt;set('_security_secured_area', serialize($token));
  $session-&gt;save();
  </code></pre>
  
  <p>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 :(</p>
  
  <p>Please help me, i tried a lot of stuff out there but nothing works. </p>