Skip to content

Commit f3ffaba

Browse files
committed
[FrameworkBundle] Add KernelBrowser::getSession()
1 parent 08b8bda commit f3ffaba

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

testing.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
753777
Making AJAX Requests
754778
....................
755779

0 commit comments

Comments
 (0)