From 12295dd912772ef8a6202f2b48e2db6f7ced6b5c Mon Sep 17 00:00:00 2001 From: sumaiazaman Date: Tue, 7 Apr 2026 11:52:06 +0600 Subject: [PATCH 1/2] [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. --- src/Illuminate/Foundation/Http/FormRequest.php | 10 ++++++++++ .../Concerns/InteractsWithTestCaseLifecycle.php | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/Illuminate/Foundation/Http/FormRequest.php b/src/Illuminate/Foundation/Http/FormRequest.php index 8ef12c152821..ba3ba284c55e 100644 --- a/src/Illuminate/Foundation/Http/FormRequest.php +++ b/src/Illuminate/Foundation/Http/FormRequest.php @@ -389,6 +389,16 @@ public static function failOnUnknownFields(bool $value = true): void static::$globalFailOnUnknownFields = $value; } + /** + * Flush the global state of the form request. + * + * @return void + */ + public static function flushState(): void + { + static::$globalFailOnUnknownFields = false; + } + /** * Set the Validator instance. * diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php index ae592732602a..131870835c47 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php @@ -11,6 +11,7 @@ use Illuminate\Foundation\Bootstrap\HandleExceptions; use Illuminate\Foundation\Bootstrap\RegisterProviders; use Illuminate\Foundation\Console\AboutCommand; +use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull; use Illuminate\Foundation\Http\Middleware\PreventRequestForgery; use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance; @@ -182,6 +183,7 @@ protected function tearDownTheTestEnvironment(): void Component::forgetComponentsResolver(); Component::forgetFactory(); ConvertEmptyStringsToNull::flushState(); + FormRequest::flushState(); Factory::flushState(); EncodedHtmlString::flushState(); EncryptCookies::flushState(); From be34d524a7f767f1e73721bdf617c8df094f3486 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 7 Apr 2026 08:29:49 -0500 Subject: [PATCH 2/2] formatting --- .../Foundation/Http/FormRequest.php | 20 +++++++++---------- .../InteractsWithTestCaseLifecycle.php | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Illuminate/Foundation/Http/FormRequest.php b/src/Illuminate/Foundation/Http/FormRequest.php index ba3ba284c55e..415ba1db8ed7 100644 --- a/src/Illuminate/Foundation/Http/FormRequest.php +++ b/src/Illuminate/Foundation/Http/FormRequest.php @@ -389,16 +389,6 @@ public static function failOnUnknownFields(bool $value = true): void static::$globalFailOnUnknownFields = $value; } - /** - * Flush the global state of the form request. - * - * @return void - */ - public static function flushState(): void - { - static::$globalFailOnUnknownFields = false; - } - /** * Set the Validator instance. * @@ -437,4 +427,14 @@ public function setContainer(Container $container) return $this; } + + /** + * Flush the global state of the form request. + * + * @return void + */ + public static function flushState(): void + { + static::$globalFailOnUnknownFields = false; + } } diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php index 131870835c47..54e264a27964 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php @@ -183,8 +183,8 @@ protected function tearDownTheTestEnvironment(): void Component::forgetComponentsResolver(); Component::forgetFactory(); ConvertEmptyStringsToNull::flushState(); - FormRequest::flushState(); Factory::flushState(); + FormRequest::flushState(); EncodedHtmlString::flushState(); EncryptCookies::flushState(); HandleCors::flushState();