Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
hot fix for laravel's bootstrap in v2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
albertcht committed Jan 14, 2019
1 parent b65df70 commit 7832737
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/Concerns/WithApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
20 changes: 18 additions & 2 deletions tests/fixtures/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php

use Mockery as m;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Contracts\Container\Container;

$kernel = new TestKernel;
$app = m::mock(Container::class);
$app->shouldReceive('bootstrap')
->once();

$app->shouldReceive('make')
->with(Kernel::class)
->once()
->andReturn($kernel);
$app->shouldReceive('bootstrapWith')
->once()
->andReturn($kernel);
$app->shouldReceive('offsetExists')
->with('foo')
->once()
Expand All @@ -17,3 +25,11 @@
$app->shouldReceive('alias');

return $app;

class TestKernel
{
public function bootstrappers()
{
return [];
}
}

0 comments on commit 7832737

Please sign in to comment.