March 23, 2020 Javier Eguiluz

In functional tests, testing protected pages requires logging in as a user. Reproducing the actual login process (e.g. typing a username and password in a login form and submitting it) makes tests slow. Symfony recommends this trick as a faster alternative, but it may not fit your needs.

That's why in Symfony 5.1 we've added a new loginUser() method to simulate the full user login inside a test. Pass the UserInterface object of the user you want to login and that's all: