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