File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -714,6 +714,29 @@ stores in the session of the test client. If you need to define custom
714
714
attributes in this token, you can use the ``tokenAttributes `` argument of the
715
715
:method: `Symfony\\ Bundle\\ FrameworkBundle\\ KernelBrowser::loginUser ` method.
716
716
717
+ You can also use an :ref: `in-memory user <security-memory-user-provider >` in your tests
718
+ by instantiating :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ InMemoryUser ` directly::
719
+
720
+ // tests/Controller/ProfileControllerTest.php
721
+ use Symfony\Component\Security\Core\User\InMemoryUser;
722
+
723
+ $client = static::createClient();
724
+ $testUser = new InMemoryUser('admin', 'password', ['ROLE_ADMIN']);
725
+ $client->loginUser($testUser);
726
+
727
+ Before doing this, you must define the in-memory user in your test environment
728
+ configuration to ensure it exists and can be authenticated::
729
+
730
+ .. code-block :: yaml
731
+
732
+ # config/packages/security.yaml
733
+ when@test :
734
+ security :
735
+ users_in_memory :
736
+ memory :
737
+ users :
738
+ admin : { password: password, roles: ROLE_ADMIN }
739
+
717
740
To set a specific firewall (``main `` is set by default)::
718
741
719
742
$client->loginUser($testUser, 'my_firewall');
You can’t perform that action at this time.
0 commit comments