Symfony 4 Functional Form Test with CSRF Token and Session

  functional-testing, php, phpunit, session, symfony

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.

Source: Symfony Questions