Skip to content

Commit 9f4c5cf

Browse files
[13.x] Add flushState to FormRequest to reset global strict mode between tests (#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>
1 parent a3a626b commit 9f4c5cf

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/Illuminate/Foundation/Http/FormRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,4 +427,14 @@ public function setContainer(Container $container)
427427

428428
return $this;
429429
}
430+
431+
/**
432+
* Flush the global state of the form request.
433+
*
434+
* @return void
435+
*/
436+
public static function flushState(): void
437+
{
438+
static::$globalFailOnUnknownFields = false;
439+
}
430440
}

src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Foundation\Bootstrap\HandleExceptions;
1212
use Illuminate\Foundation\Bootstrap\RegisterProviders;
1313
use Illuminate\Foundation\Console\AboutCommand;
14+
use Illuminate\Foundation\Http\FormRequest;
1415
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
1516
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
1617
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance;
@@ -183,6 +184,7 @@ protected function tearDownTheTestEnvironment(): void
183184
Component::forgetFactory();
184185
ConvertEmptyStringsToNull::flushState();
185186
Factory::flushState();
187+
FormRequest::flushState();
186188
EncodedHtmlString::flushState();
187189
EncryptCookies::flushState();
188190
HandleCors::flushState();

0 commit comments

Comments
 (0)