Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,30 @@ To set a specific firewall (``main`` is set by default)::
By design, the ``loginUser()`` method doesn't work when using stateless firewalls.
Instead, add the appropriate token/header in each ``request()`` call.

.. _testing_setup_the_session:

Setup the session
.................

The client provides a ``getSession()`` method, which allows you to setup the session before performing the request::

// tests/Controller/FormControllerTest.php
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class FormControllerTest extends WebTestCase
{
public function testSetupCsrfTokenBeforeFormSubmit(): void
{
$client = self::createClient();

$session = $client->getSession();
$session->set('_csrf/form', 'fhr8d5sha3a69tpv24s5');
$session->save();

$client->request('POST', '/form', ['form' => ['_token' => 'fhr8d5sha3a69tpv24s5']]);
}
}

Making AJAX Requests
....................

Expand Down