diff --git a/src/Concerns/WithApplication.php b/src/Concerns/WithApplication.php index 63f0cdcd..a7e28906 100644 --- a/src/Concerns/WithApplication.php +++ b/src/Concerns/WithApplication.php @@ -28,7 +28,8 @@ trait WithApplication protected function bootstrap() { if ($this->framework === 'laravel') { - $this->app->bootstrap(); + $bootstrappers = $this->getBootstrappers(); + $this->app->bootstrapWith($bootstrappers); } else { // for Lumen 5.7 // https://github.com/laravel/lumen-framework/commit/42cbc998375718b1a8a11883e033617024e57260#diff-c9248b3167fc44af085b81db2e292837 @@ -137,4 +138,24 @@ protected function preResolveInstances() } } } + + /** + * Get bootstrappers. + * + * @return array + * @throws \ReflectionException + */ + protected function getBootstrappers() + { + $kernel = $this->getApplication()->make(Kernel::class); + + $reflection = new \ReflectionObject($kernel); + $bootstrappersMethod = $reflection->getMethod('bootstrappers'); + $bootstrappersMethod->setAccessible(true); + $bootstrappers = $bootstrappersMethod->invoke($kernel); + + array_splice($bootstrappers, -2, 0, ['Illuminate\Foundation\Bootstrap\SetRequestForConsole']); + + return $bootstrappers; + } } diff --git a/tests/fixtures/bootstrap/app.php b/tests/fixtures/bootstrap/app.php index aafbe347..79e6824b 100644 --- a/tests/fixtures/bootstrap/app.php +++ b/tests/fixtures/bootstrap/app.php @@ -1,11 +1,19 @@ shouldReceive('bootstrap') - ->once(); + +$app->shouldReceive('make') + ->with(Kernel::class) + ->once() + ->andReturn($kernel); +$app->shouldReceive('bootstrapWith') + ->once() + ->andReturn($kernel); $app->shouldReceive('offsetExists') ->with('foo') ->once() @@ -17,3 +25,11 @@ $app->shouldReceive('alias'); return $app; + +class TestKernel +{ + public function bootstrappers() + { + return []; + } +}