From 53e3246f1c88d2598bd4c3d4c1eace2769aa9b14 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 17 Jan 2024 22:57:12 +0800 Subject: [PATCH] [11.x] Flush `RegisterProviders` bootstrapper state between tests (#49719) * [11.x] Flush `RegisterProviders` bootstrapper state between tests. Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * Update RegisterProviders.php * Update TestCase.php --------- Signed-off-by: Mior Muhammad Zaki Co-authored-by: Taylor Otwell --- .../Foundation/Bootstrap/RegisterProviders.php | 12 ++++++++++++ src/Illuminate/Foundation/Testing/TestCase.php | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php b/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php index ddad0ffabcc5..700651913caf 100644 --- a/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php +++ b/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php @@ -79,4 +79,16 @@ public static function merge(array $providers, ?string $bootstrapProviderPath = array_merge(static::$merge, $providers) ))); } + + /** + * Flush the bootstrapper's global state. + * + * @return void + */ + public static function flushState() + { + static::$bootstrapProviderPath = null; + + static::$merge = []; + } } diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index bd0c63288b30..93805335b8ff 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Application; use Illuminate\Foundation\Bootstrap\HandleExceptions; +use Illuminate\Foundation\Bootstrap\RegisterProviders; use Illuminate\Foundation\Console\AboutCommand; use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull; use Illuminate\Foundation\Http\Middleware\TrimStrings; @@ -248,6 +249,7 @@ protected function tearDown(): void ConvertEmptyStringsToNull::flushState(); HandleExceptions::flushState(); Queue::createPayloadUsing(null); + RegisterProviders::flushState(); Sleep::fake(false); TrimStrings::flushState();