Description
Symfony version(s) affected
5.4.0-RC1
Description
It seems that there were some changes in the Session that change the initialization process in the KernelBrowser or other related services. Not sure if this is a BC break, a bug, or anything else, so reporting it anyway just in case.
How to reproduce
- Create a Controller that makes some checks on the Session, one
$session->get('some_key')
should suffice. - Create a functional test implementing
WebTestCase
- Get the HTTP client using
$client = self::createClient()
- Modify the session with something like
$client->getContainer()->get('session')->set('some_key');
- Save the session with
$client->getContainer()->get('session')->save()
- Make an HTTP request with
$client->request(...)
on the route that's defined by the aforementioned Controller - In your Controller, using a debugger or
dump()
statements, you'll notice that the value ofsome_key
is not set in the Session
Additionnally, if you want to reproduce it with the project that made me discover the "issue" (not sure if it's a BC break or not), you can clone this project: https://github.com/Pierstoval/CorahnRin/blob/5.4-reproducer/tests/CorahnRin/Step/AbstractStepTest.php#L33-L35
To reproduce using the project, here are the steps:
- You need Docker and Make to install it, and do it via
make install
. - Comment the three lines 33, 34 and 35 in the
Tests\CorahnRin\Step\AbstractStepTest
class - Run only the
Tests\CorahnRin\Step\Step07SetbacksTest::testNoSetback
test
The test will fail because the GeneratorController
(coming from the PierstovalCharacterManagerBundle
) checks the session to get the values from $session->get('character.corahn_rin')
, which is supposed to be already set in the Tests\CorahnRin\Step\AbstractStepTest::submitAction()
method beforehand.
Possible Solution
The current workaround I'm using is to make an HTTP request to any URL of the project that sets the session, but does not need to get elements from it. Basically, a GET request on most pages that check if user is logged in should do the trick.
Additional Context
The same happens if you make an HTTP request and execute $client->restart()
, it acts just like the Client was recreated, maybe because of the lack of Cookie HTTP header.