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 8be81ffb1..f6b863bd6 100644 --- a/src/foundation/src/Testing/TestCase.php +++ b/src/foundation/src/Testing/TestCase.php @@ -67,6 +67,18 @@ 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(array_values(array_diff( + Application::DEFAULT_BOOTSTRAPPERS, + [\Hypervel\Foundation\Bootstrap\HandleExceptions::class], + ))); + } } /**