Symfony 4 Functional Form Test with CSRF Token and Session

I am using a symfony 4.4 with the form bundle and want to make some functional tests.

My form has multiple steps and I want to perform a complete form until the success message. But with csrf_protection:true I can’t even get to page 2. If I disable it for the test environment I can get to page 2. If I dump my session at page 2, I can see, that it is empty. Here is an example of my test:

$client = static::createClient();
$client->request('GET', '/test');
$crawler = $client->submitForm('Next', ['name' => 'Max Mustermann']); // => lands on step2
$crawler = $client->submitForm('Next', ['email' => '[email protected]']); // => lands back on step 1 with emtpy form. So session is empty

Does anyone have an idea what is wrong here?
This page says, that is have to work, but it doesn’t.
https://symfony.com/doc/4.4/components/http_foundation/session_testing.html#functional-testing

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *