I'm running into an issue when trying to run a controller based unit test on a controller method that implements Sessions.
In this case, here is the controller method:
/**
* @Route("/api/logout")
*/
public function logoutAction()
{
$session = new Session();
$session->clear();
return $this->render('PassportApiBundle:Login:logout.html.twig');
}
And the functional test:
public function testLogout()
{
$client = static::createClient();
$crawler = $client->request('GET', '/api/logout');
$this->assertTrue($client->getResponse()->isSuccessful());
}
The error that is produced:
Failed to start the session because headers have already been sent. (500 Internal Server Error)
I've tried placing in $this->app['session.test'] = true;
into the test, but still no go. Has anyone tried resolving an issue like this to unit testing a controller that uses a session?