I'm trying to play a little bit with the functional test in Symfony and i'm currently facing a problem with my sessions. I execute a piece of code, which seems to be working, but nothing is stored inside the session of my container.
I have a form where you set datas. When you submit it, it checks the values and store it inside sessions. Then it redirects to another page where these values stored in session are needed.
The purpose of my test is to check the session.
<?php
namespace Acme\TestBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
use Symfony\Component\HttpFoundation\Session\Session;
class FrontControllerTest extends WebTestCase
{
public function testForm()
{
$client = static::createClient();
$session = $client->getContainer()->get('session');
$crawler = $client->request('GET', '/setParameters');
$form = $crawler->selectButton('Submit')->form();
$form['myForm[firstname]']->setValue('Ben');
$form['myForm[lastname]']->setValue('H');
$client->submit($form);
//I tested and my controller is fully going through the submit handler
//which check the values and save it into the session
//Things are 100% sure there. Then it redirects to another page which check those values.
$values = $client->getContainer()->get('session')->get('parameters'); //NULL
$this->assertEquals($values['firstname'], 'Ben'); //false
$this->assertEquals($values['lastname'], 'H'); //false
}
}
Actually it's not working at all, it seems like i can't store anything in the session and retrieve it.
Can someone help me with it ? Thank's.
$this->assertEquals(302, $client->getResponse()->getStatusCode(), "correct response code");