File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -750,6 +750,30 @@ To set a specific firewall (``main`` is set by default)::
750750 By design, the ``loginUser() `` method doesn't work when using stateless firewalls.
751751 Instead, add the appropriate token/header in each ``request() `` call.
752752
753+ .. _testing_setup_the_session :
754+
755+ Setup the session
756+ .................................
757+
758+ The client provides a ``getSession() `` method, which allows you to setup the session before performing the request::
759+
760+ // tests/Controller/FormControllerTest.php
761+ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
762+
763+ class FormControllerTest extends WebTestCase
764+ {
765+ public function testSetupCsrfTokenBeforeFormSubmit(): void
766+ {
767+ $client = self::createClient();
768+
769+ $session = $client->getSession();
770+ $session->set('_csrf/form', 'fhr8d5sha3a69tpv24s5');
771+ $session->save();
772+
773+ $client->request('POST', '/form', ['form' => ['_token' => 'fhr8d5sha3a69tpv24s5']]);
774+ }
775+ }
776+
753777Making AJAX Requests
754778....................
755779
You can’t perform that action at this time.
0 commit comments