Skip to content

[13.x] Keep the assertion failure message when session errors are JSON serialized - #61201

Open
lazerg wants to merge 1 commit into
laravel:13.xfrom
lazerg:fix/test-response-assert-json-session-errors
Open

[13.x] Keep the assertion failure message when session errors are JSON serialized#61201
lazerg wants to merge 1 commit into
laravel:13.xfrom
lazerg:fix/test-response-assert-json-session-errors

Conversation

@lazerg

@lazerg lazerg commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Store::save() replaces the in-memory ViewErrorBag with a plain array when the session serializes to JSON, and never puts the object back. TestResponse::session() hides this because it restarts the session, which runs marshalErrorBag() and rebuilds the bag, but TestResponseAssert::injectResponseContext() reads the redirect response's session directly and calls ->all() on whatever is there.

So on a failing assertion against a redirect carrying validation errors, the helper throws Error: Call to a member function all() on array and that replaces the ExpectationFailedException it was meant to enrich. The real failure message, the expected and actual values and the validation messages are all gone, and the trail points at a framework internal rather than the test. It only shows up once an assertion is already failing, so a green suite never surfaces it, and json is the shipped default for new applications.

Starting the session before reading the errors lets the store marshal the bag back, so the assertion message keeps both the original failure and the validation errors.

Fixes #61200

@lazerg
lazerg force-pushed the fix/test-response-assert-json-session-errors branch from ec69874 to 25a26c8 Compare August 15, 2026 08:40
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.

TestResponseAssert crashes on flashed ViewErrorBag when session serialization is json

1 participant