File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -714,6 +714,27 @@ stores in the session of the test client. If you need to define custom
714714attributes in this token, you can use the ``tokenAttributes `` argument of the
715715:method: `Symfony\\ Bundle\\ FrameworkBundle\\ KernelBrowser::loginUser ` method.
716716
717+ You can also use :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ InMemoryUser ` but you have to define those in the configuration first::
718+
719+ .. code-block :: yaml
720+
721+ # config/packages/security.yaml
722+ when@test :
723+ security :
724+ users_in_memory :
725+ memory :
726+ users :
727+ admin : { password: password, roles: ROLE_ADMIN }
728+
729+ and then log the user with::
730+
731+ // tests/Controller/ProfileControllerTest.php
732+ use Symfony\Component\Security\Core\User\InMemoryUser;
733+
734+ $client = static::createClient();
735+ $testUser = new InMemoryUser('admin', 'password', ['ROLE_ADMIN']);
736+ $client->loginUser($testUser);
737+
717738To set a specific firewall (``main `` is set by default)::
718739
719740 $client->loginUser($testUser, 'my_firewall');
You can’t perform that action at this time.
0 commit comments