Skip to content

[12.x] Add assertRedirectBackWithErrors to TestResponse#55987

Merged
taylorotwell merged 5 commits into
laravel:12.xfrom
AhmedAlaa4611:assert-redirect-back-with-errors
Jun 12, 2025
Merged

[12.x] Add assertRedirectBackWithErrors to TestResponse#55987
taylorotwell merged 5 commits into
laravel:12.xfrom
AhmedAlaa4611:assert-redirect-back-with-errors

Conversation

@AhmedAlaa4611

Copy link
Copy Markdown
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
Copy Markdown
Member

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

@AhmedAlaa4611

AhmedAlaa4611 commented Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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