From 9baec6733930510321077c0bdc4e4371cdc60aec Mon Sep 17 00:00:00 2001 From: Richard Anabeto Opoku Date: Tue, 7 Jul 2026 18:08:49 +0000 Subject: [PATCH 1/2] Bootstrap the application when tests refresh it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refreshApplication() only created the application. The bootstrappers (LoadEnvironmentVariables, LoadConfiguration, RegisterFacades, RegisterProviders, GenerateProxies, BootProviders) only run on the HTTP and console boot paths, so on the test path the facade root was never bound and the first facade call in setUp() failed with "A facade root has not been set" — the default ExampleTest of a fresh application fails out of the box. Bootstrap the freshly-created application in refreshApplication(). HandleExceptions is deliberately omitted so PHPUnit reports failures instead of the Swoole error handler. --- src/foundation/src/Testing/TestCase.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/foundation/src/Testing/TestCase.php b/src/foundation/src/Testing/TestCase.php index 8be81ffb1..0fa71af7f 100644 --- a/src/foundation/src/Testing/TestCase.php +++ b/src/foundation/src/Testing/TestCase.php @@ -67,6 +67,22 @@ protected function setUp(): void protected function refreshApplication(): void { $this->app = $this->createApplication(); + + // Bootstrap the freshly-created app for the test context. Without this the + // bootstrappers (RegisterFacades, RegisterProviders, BootProviders, …) never + // run in tests — only on the HTTP/console boot path — so the facade root is + // never bound and the very next facade call in setUp fails. HandleExceptions is + // deliberately omitted so PHPUnit (not the app's Swoole error handler) reports failures. + if (! $this->app->hasBeenBootstrapped()) { + $this->app->bootstrapWith([ + \Hypervel\Foundation\Bootstrap\LoadEnvironmentVariables::class, + \Hypervel\Foundation\Bootstrap\LoadConfiguration::class, + \Hypervel\Foundation\Bootstrap\RegisterFacades::class, + \Hypervel\Foundation\Bootstrap\RegisterProviders::class, + \Hypervel\Di\Bootstrap\GenerateProxies::class, + \Hypervel\Foundation\Bootstrap\BootProviders::class, + ]); + } } /** From b141d5314bdc8c95921694462d6bebf3e8b2dfc0 Mon Sep 17 00:00:00 2001 From: Richard Anabeto Opoku Date: Wed, 8 Jul 2026 03:00:05 +0000 Subject: [PATCH 2/2] Share the default bootstrapper sequence across boot paths The HTTP kernel, the console kernel, and the test path each hardcoded the same bootstrapper list. Move it to Application::DEFAULT_BOOTSTRAPPERS so the three paths cannot drift; the test path keeps excluding HandleExceptions. --- src/foundation/src/Application.php | 18 ++++++++++++++++++ src/foundation/src/Console/Kernel.php | 10 +--------- src/foundation/src/Http/Kernel.php | 10 +--------- src/foundation/src/Testing/TestCase.php | 12 ++++-------- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/foundation/src/Application.php b/src/foundation/src/Application.php index 6b1b02105..9d5ca143e 100644 --- a/src/foundation/src/Application.php +++ b/src/foundation/src/Application.php @@ -45,6 +45,24 @@ class Application extends Container implements ApplicationContract, CachesConfig */ public const VERSION = '0.4'; + /** + * The default bootstrap sequence for the application. + * + * Shared by the HTTP and console kernels and by the testing + * infrastructure so the boot paths cannot drift apart. + * + * @var array + */ + public const DEFAULT_BOOTSTRAPPERS = [ + \Hypervel\Foundation\Bootstrap\LoadEnvironmentVariables::class, + \Hypervel\Foundation\Bootstrap\LoadConfiguration::class, + \Hypervel\Foundation\Bootstrap\HandleExceptions::class, + \Hypervel\Foundation\Bootstrap\RegisterFacades::class, + \Hypervel\Foundation\Bootstrap\RegisterProviders::class, + \Hypervel\Di\Bootstrap\GenerateProxies::class, + \Hypervel\Foundation\Bootstrap\BootProviders::class, + ]; + /** * The base path for the Hypervel installation. */ diff --git a/src/foundation/src/Console/Kernel.php b/src/foundation/src/Console/Kernel.php index d42b37f17..be918e7de 100644 --- a/src/foundation/src/Console/Kernel.php +++ b/src/foundation/src/Console/Kernel.php @@ -88,15 +88,7 @@ class Kernel implements KernelContract /** * The console application bootstrappers. */ - protected array $bootstrappers = [ - \Hypervel\Foundation\Bootstrap\LoadEnvironmentVariables::class, - \Hypervel\Foundation\Bootstrap\LoadConfiguration::class, - \Hypervel\Foundation\Bootstrap\HandleExceptions::class, - \Hypervel\Foundation\Bootstrap\RegisterFacades::class, - \Hypervel\Foundation\Bootstrap\RegisterProviders::class, - \Hypervel\Di\Bootstrap\GenerateProxies::class, - \Hypervel\Foundation\Bootstrap\BootProviders::class, - ]; + protected array $bootstrappers = \Hypervel\Foundation\Application::DEFAULT_BOOTSTRAPPERS; public function __construct( protected ContainerContract $app, diff --git a/src/foundation/src/Http/Kernel.php b/src/foundation/src/Http/Kernel.php index 02ec963dc..6eafcc662 100644 --- a/src/foundation/src/Http/Kernel.php +++ b/src/foundation/src/Http/Kernel.php @@ -42,15 +42,7 @@ class Kernel implements KernelContract * * @var string[] */ - protected array $bootstrappers = [ - \Hypervel\Foundation\Bootstrap\LoadEnvironmentVariables::class, - \Hypervel\Foundation\Bootstrap\LoadConfiguration::class, - \Hypervel\Foundation\Bootstrap\HandleExceptions::class, - \Hypervel\Foundation\Bootstrap\RegisterFacades::class, - \Hypervel\Foundation\Bootstrap\RegisterProviders::class, - \Hypervel\Di\Bootstrap\GenerateProxies::class, - \Hypervel\Foundation\Bootstrap\BootProviders::class, - ]; + protected array $bootstrappers = \Hypervel\Foundation\Application::DEFAULT_BOOTSTRAPPERS; /** * The application's middleware stack. diff --git a/src/foundation/src/Testing/TestCase.php b/src/foundation/src/Testing/TestCase.php index 0fa71af7f..f6b863bd6 100644 --- a/src/foundation/src/Testing/TestCase.php +++ b/src/foundation/src/Testing/TestCase.php @@ -74,14 +74,10 @@ protected function refreshApplication(): void // never bound and the very next facade call in setUp fails. HandleExceptions is // deliberately omitted so PHPUnit (not the app's Swoole error handler) reports failures. if (! $this->app->hasBeenBootstrapped()) { - $this->app->bootstrapWith([ - \Hypervel\Foundation\Bootstrap\LoadEnvironmentVariables::class, - \Hypervel\Foundation\Bootstrap\LoadConfiguration::class, - \Hypervel\Foundation\Bootstrap\RegisterFacades::class, - \Hypervel\Foundation\Bootstrap\RegisterProviders::class, - \Hypervel\Di\Bootstrap\GenerateProxies::class, - \Hypervel\Foundation\Bootstrap\BootProviders::class, - ]); + $this->app->bootstrapWith(array_values(array_diff( + Application::DEFAULT_BOOTSTRAPPERS, + [\Hypervel\Foundation\Bootstrap\HandleExceptions::class], + ))); } }