laravel / browser-kit-testing

Provides backwards compatibility for BrowserKit testing in the latest Laravel release.
MIT License
508 stars 75 forks source link

Infinite redirect loop when testing a controller utilizing back() method on 5.8 #96

Closed okdewit closed 5 years ago

okdewit commented 5 years ago

See comment on https://github.com/laravel/framework/issues/27731#issuecomment-472908169.

Given some controller route with a return redirect()->back():

<?php
public function archive($model)
{
    $model->archive();
    return redirect()->back();
}

And a browserkit test:

<?php
$this->actingAs($user)
    ->visit('model.show')
    ->click('archive')
    ->see(...)

This is a simple "show" route + view, with an "archive" button + GET route which is this case is set up to just do a redirect()->back() again to the "show" page (I know it's not super REST-compliant, it's a legacy system).

After migrating to Laravel 5.8, I noticed that some tests would rapidly fill up storage/framework/session directory with session files (hundreds of gigabytes).

It seems something changed regarding the way the session stores the previous URL.

Both with Laravel 5.7.21 and 5.8.3 everything works correctly when used with an actual browser, the "previous URL" on the archive action is identical to the "show" route.

When using the ->visit(...)->click(...) methods in browserkit tests, the previous URL during the click request is the "archive" route itself, which leads to an infinite redirect loop.

driesvints commented 5 years ago

Can you maybe provide the routes and controller for this? Would help to reproduce it.

fitztrev commented 5 years ago

Possibly related laravel/framework#27894

okdewit commented 5 years ago

My issue was fixed by https://github.com/laravel/framework/pull/27935 in Laravel 5.8.5 👍