I’m writing a functional test for an action that uses Symfony2’s session service to fetch data. In my test class’s setUp method, I call $this->get('session')->set('foo', 'bar');. If I output all the session data (using print_r($this->get('session')->all());) either in setUp or in the actual test method, I get back foo => bar. But if I try outputting the session data from the action being tested, I get back an empty array. Does anyone know why this is happening, and how I can prevent it?
I should note that if I call $_SESSION['foo'] = 'bar' from within setUp() the data is persisted and I can access it from the action – this problem seems local to Symfony2’s session service.
Firstly try using your client’s container (I’m assuming you’re using WebTestCase):
If it still doesn’t work try saving the session:
I didn’t try it in functional tests but that’s how it works in Behat steps.