Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Add followingRedirects() method #21771

Merged
merged 2 commits into from
Oct 22, 2017
Merged

Conversation

dwightwatson
Copy link
Contributor

This adds a test helper method called followingRedirects() that will instruct the the test case to follow any redirect responses automatically. It can be chained prior to making a HTTP request and it's named to read more sentence-like.

$response = $this->followingRedirects()->post('/login', ['email' => '[email protected]']);

$response->assertSee('Welcome back, John.');

From memory a similar test helper used to exist in an earlier iteration of Laravel's test suite, so this is just returning the functionality. It was prompted by #18016.

@sisve
Copy link
Contributor

sisve commented Oct 21, 2017

Are you thinking of the old laravel/browser-kit-testing which was default in 5.3? It has a followRedirects() method.

@dwightwatson
Copy link
Contributor Author

That's the one. Happy to match the naming too if preferred.

@tillkruss tillkruss changed the title Add followingRedirects() method [5.5] Add followingRedirects() method Oct 21, 2017
@taylorotwell
Copy link
Member

I don't really like how if you call this in one test method it's not going to apply to all test methods that run after that in that class. How would I disable it? Shouldn't it be disabled after each test?

@dwightwatson
Copy link
Contributor Author

I had tested for that and it appeared to reset between tests in the same class for me. However, I've now explicitly set followRedirects back to false after each request made. Let me know if that feels better to you or if there's another approach you'd rather me take.

@taylorotwell taylorotwell merged commit ea379df into laravel:5.5 Oct 22, 2017
@dwightwatson dwightwatson deleted the 5.5 branch October 23, 2017 03:46
@deleugpn
Copy link
Contributor

Clean and sweet.

@KuenzelIT
Copy link

So there is no possibility to make all test methods follow redirects automatically right now?

@mgralikowski
Copy link

mgralikowski commented Aug 12, 2020

Is it normal that this method persists an app state between calls? Ex when I put dump into main middleware It will be fired X times where X is numbers of redirects. Now when I set something in this middleware for example Menu (by library) declaration it is called twice and the second call sees already defined menu. It is easy to check also by declaring function - PHPUnit will return error " Cannot redeclare App\Http\Middleware\sampleFunctionName() (previously declared in \app\Http\Middleware\MenuGen
erator.php:56) "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants