B
B
BonBon Slick2018-05-19 14:09:41
symfony
BonBon Slick, 2018-05-19 14:09:41

How to test redirects?

Something like this only for Symphony. https://medium.com/@splatEric/laravel-testing-tidb...
We have 2 firewalls, 1 for the admin panel and another for the API. In the second case, everything is simple, the redirect does the client-side, because it does not have login data, so you can just test the response, there will be something like ACCESS_DENIED response.
But what about the translation to the login page? How can you test a redirect to the login page if the user tried to go to a secure route?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2018-05-19
@BonBonSlick

You can write a simple functional test: https://symfony.com/doc/current/testing.html#your-...

public function testRedirectsNotAuthenticatedUsersToLoginPage()
{
    $client = static::createClient();

    $client->request('GET', '/account/secrets');

    $this->assertTrue($client->getResponse()->isRedirect('/login'));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question