Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,27 @@
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 }

Check failure on line 727 in testing.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Cache Warmup] In SecurityExtension.php line 98: The SecurityBundle is enabled but is not configured. Try running "composer symfony:recipes:install symfony/security-bundle".
and then log the user with::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/log/log in/? "logging" the user sounds more like writing the user into a log?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ... but while merging we did a minor change to reverse the original order (instead of showing config first and then how to log in, we did the opposite) so we tweaked that.


// 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');
Expand Down
Loading