How can I persist data with Symfony2's session service during a functional test?

后端 未结 2 1920
挽巷
挽巷 2021-01-19 04:39

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(\

2条回答
  •  春和景丽
    2021-01-19 04:58

    Firstly try using your client's container (I'm assuming you're using WebTestCase):

    $client = static::createClient();
    $container = $client->getContainer();
    

    If it still doesn't work try saving the session:

    $session = $container->get('session');
    $session->set('foo', 'bar');
    $session->save();
    

    I didn't try it in functional tests but that's how it works in Behat steps.

提交回复
热议问题