I had a similar problem (logging in properly) what solved it finally for me was to change the way I log in(it's based on http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html but I handle the session differently):
public function setUp() {
parent::setUp();
$this->em = $this->get('doctrine')->getManager();
$this->client = static::createClient(array('environment' => 'test'));
}
protected function logIn() {
$repo = $this->em->getRepository('XXXXXXX');
$user = $repo->findOneByUsername('YYYYYYY');
$session = new Session(new MockFileSessionStorage());
$firewall = 'main';
$token = new UsernamePasswordToken($user, null, $firewall, array('ROLE_ADMIN'));
$this->client->getContainer()->get('security.context')->setToken($token);
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$this->client->getContainer()->set('session', $session);
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
return $user;
}