Closed
Description
Symfony version(s) affected: 5.3.1
Description
Since the introduction of storage_factory_id
to replace storage_id
, it's not possible to switch to another user in the tests any more
I have pushed a sample project which reproduces the issue here: https://github.com/guillaumesmo/symfony-login-user-issue
How to reproduce
in a controller:
/**
* @Route("/admin-page")
* @Security("is_granted('ROLE_ADMIN')")
*/
public function adminPage()
{
return new Response('OK');
}
in a WebTestCase:
$client = self::createClient();
$client->loginUser(new InMemoryUser('admin', 'password', ['ROLE_ADMIN']));
$client->request('GET', '/admin-page');
self::assertResponseIsSuccessful();
$client->loginUser(new InMemoryUser('other', 'password', ['ROLE_OTHER']));
$client->request('GET', '/admin-page');
self::assertResponseStatusCodeSame(403);
run bin/phpunit:
There was 1 failure:
1) App\Tests\Controller\DefaultControllerTest::test
Failed asserting that the Response status code is 403.
HTTP/1.1 200 OK
Now in config/packages/framework.yaml, revert to the Symfony 5.2 default config:
- remove the line
storage_factory_id: session.storage.factory.native
- change
storage_factory_id: session.storage.factory.mock_file
tostorage_id: session.storage.mock_file
run bin/phpunit:
OK (1 test, 2 assertions)