From 124be08d977cac7ef6296b6ed35496abf8443e05 Mon Sep 17 00:00:00 2001 From: Peter Potrowl Date: Thu, 19 Jun 2025 21:53:06 +0200 Subject: [PATCH] [Testing] Indicate how to use InMemoryUser in WebTestCase --- testing.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/testing.rst b/testing.rst index 9356f2013a7..862d66d59b8 100644 --- a/testing.rst +++ b/testing.rst @@ -714,6 +714,27 @@ stores in the session of the test client. If you need to define custom attributes in this token, you can use the ``tokenAttributes`` argument of the :method:`Symfony\\Bundle\\FrameworkBundle\\KernelBrowser::loginUser` method. +You can also use :class:`Symfony\\Component\\Security\\Core\\User\\InMemoryUser` but you have to define those in the configuration first:: + +.. code-block:: yaml + + # config/packages/security.yaml + when@test: + security: + users_in_memory: + memory: + users: + admin: { password: password, roles: ROLE_ADMIN } + +and then log the user with:: + + // tests/Controller/ProfileControllerTest.php + use Symfony\Component\Security\Core\User\InMemoryUser; + + $client = static::createClient(); + $testUser = new InMemoryUser('admin', 'password', ['ROLE_ADMIN']); + $client->loginUser($testUser); + To set a specific firewall (``main`` is set by default):: $client->loginUser($testUser, 'my_firewall'); 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