Skip to content

Commit 124be08

Browse files
peter17javiereguiluz
authored andcommitted
[Testing] Indicate how to use InMemoryUser in WebTestCase
1 parent bdc7813 commit 124be08

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

testing.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,27 @@ stores in the session of the test client. If you need to define custom
714714
attributes 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+
717738
To set a specific firewall (``main`` is set by default)::
718739

719740
$client->loginUser($testUser, 'my_firewall');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy