Skip to content

[12.x] Add assertRedirectBackWithErrors to TestResponse #55987

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

Merged

Conversation

AhmedAlaa4611
Copy link
Contributor

Description

This PR introduces a new assertRedirectBackWithErrors() method to streamline testing redirect-back responses that include validation errors.

Currently, developers need to write:

$response->assertRedirectBack();
$response->assertSessionHasErrors([
    // ...
]);

With this addition, the test can be simplified to:

$response->assertRedirectBackWithErrors([
    // ...
]);

Internally, this method simply calls assertRedirectBack() and assertSessionHasErrors(), so it's a convenience wrapper that improves test readability and reduces duplication.

About tests

I didn't include a separate test for this method since it delegates entirely to two existing, well-tested assertions.

@taylorotwell
Copy link
Member

It raises more permutations in my mind... should there also be assertRedirectBackWithoutErrors?

@AhmedAlaa4611
Copy link
Contributor Author

AhmedAlaa4611 commented Jun 11, 2025

@taylorotwell

It raises more permutations in my mind... should there also be assertRedirectBackWithoutErrors?

That's a good point; I hadn't considered that, but I agree it makes sense for completeness and symmetry. I'm happy to add assertRedirectBackWithoutErrors() as well.

Should I make it in the same PR or in another PR?

@taylorotwell taylorotwell merged commit 4f4d556 into laravel:12.x Jun 12, 2025
60 checks passed
@taylorotwell
Copy link
Member

I got it! Thanks.

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.

2 participants