@@ -714,7 +714,18 @@ 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::
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::
718729
719730.. code-block :: yaml
720731
@@ -726,15 +737,6 @@ You can also use :class:`Symfony\\Component\\Security\\Core\\User\\InMemoryUser`
726737 users :
727738 admin : { password: password, roles: ROLE_ADMIN }
728739
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-
738740 To set a specific firewall (``main `` is set by default)::
739741
740742 $client->loginUser($testUser, 'my_firewall');
0 commit comments