I'm testing my controller functions with Phpunit in Symfony 2.8. I set some attributes in my session using MockFileSessionStorage() and it works fine during my first request, but then when I send a form I can't reach my attributes in my controller, it returns null.
Here's my test :
class CheckoutControllerTest extends WebTestCase
{
public function setClient()
{
return $client = static::createClient(array(), array(
'PHP_AUTH_USER' => static::DEMO_USER,
'PHP_AUTH_PW' => static::DEMO_PASSWORD,
));
}
public function testSetupCart()
{
$client = $this->setClient();
//set session
$session = new Session(new MockFileSessionStorage());
$container = $client->getContainer();
$session->set("shopbundle_cart_id", "1");
$session->set("shopbundle_current_event_hash", "hash");
$container->set('session', $session);
$crawler = $client->request('GET', 'http://ift.tt/2dZuFLB');
$this->assertTrue($client->getResponse()->isSuccessful());
//I can get my session attributes in my controller
$form = $crawler->selectButton('Continue')->form();
$client->submit($form);
//in my controller handling the form submit, i can't get my attributes
$client->followRedirect();
$this->assertTrue($client->getResponse()->isSuccessful());
}
I access the attributes in both controllers like this : $cartId = $this->get("session")->get("shopbundle_cart_id", null);. The form is submitted in POST.
Here is my config_test.yml file :
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.mock_file
profiler:
collect: false
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
Can you help me finding out what is wrong ?
Aucun commentaire:
Enregistrer un commentaire