[13.x] Add flushState to FormRequest to reset global strict mode between tests#59574
Merged
taylorotwell merged 2 commits intoApr 7, 2026
Merged
Conversation
…een tests FormRequest::failOnUnknownFields() sets a static flag that persists across tests. Without a flushState() method and a call in the test lifecycle teardown, enabling strict mode in one test leaks into all subsequent tests.
crynobone
added a commit
to orchestral/testbench-core
that referenced
this pull request
Apr 8, 2026
…en tests Reference: laravel/framework#59574 Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
crynobone
added a commit
to orchestral/testbench-core
that referenced
this pull request
Apr 8, 2026
…en tests (#403) * Add `flushState()` to `FormRequest` to reset global strict mode between tests Reference: laravel/framework#59574 Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * bump laravel version Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> --------- Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
jonagoldman
pushed a commit
to deplox/laravel-framework
that referenced
this pull request
Apr 30, 2026
…een tests (laravel#59574) * [13.x] Add flushState to FormRequest to reset global strict mode between tests FormRequest::failOnUnknownFields() sets a static flag that persists across tests. Without a flushState() method and a call in the test lifecycle teardown, enabling strict mode in one test leaks into all subsequent tests. * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #59430 added
FormRequest::failOnUnknownFields()which sets a static$globalFailOnUnknownFieldsflag. This flag persists across tests because FormRequest has noflushState()method and isn't included in the test lifecycle teardown.The Bug
The Fix
flushState()method to FormRequest that resets$globalFailOnUnknownFieldsInteractsWithTestCaseLifecycleteardown alongside all otherflushState()callsContext
Every other class with static state has
flushState()called in the test teardown:ConvertEmptyStringsToNull::flushState()TrimStrings::flushState()EncryptCookies::flushState()PreventRequestForgery::flushState()Validator::flushState()FormRequest was missed because
failOnUnknownFields()was just added in #59430.Changes
src/Illuminate/Foundation/Http/FormRequest.php— AddflushState()methodsrc/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php— CallFormRequest::flushState()in teardown