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

Commit

Permalink
Merge pull request #189 from swooletw/develop
Browse files Browse the repository at this point in the history
add support for Lumen 5.7
  • Loading branch information
albertcht authored Jan 13, 2019
2 parents 391e168 + b65df70 commit 92d93f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 50 deletions.
32 changes: 6 additions & 26 deletions src/Concerns/WithApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ trait WithApplication

/**
* Bootstrap framework.
*
* @throws \ReflectionException
*/
protected function bootstrap()
{
if ($this->framework === 'laravel') {
$bootstrappers = $this->getBootstrappers();
$this->app->bootstrapWith($bootstrappers);
$this->app->bootstrap();
} else {
// for Lumen 5.7
// https://github.com/laravel/lumen-framework/commit/42cbc998375718b1a8a11883e033617024e57260#diff-c9248b3167fc44af085b81db2e292837
if (method_exists($this->app, 'boot')) {
$this->app->boot();
}
if (is_null(Facade::getFacadeApplication())) {
$this->app->withFacades();
}
Expand Down Expand Up @@ -75,28 +77,6 @@ public function setApplication(Container $app)
$this->app = $app;
}

/**
* 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;
}

/**
* Set framework.
*
Expand Down
6 changes: 1 addition & 5 deletions tests/Server/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,14 @@ public function testOnWorkerStart()
public function testLoadApplication()
{
$server = $this->getServer();
$this->getManager();

$container = $this->getContainer($this->getServer(), $this->getConfig());
$container = $this->getContainer($server, $this->getConfig());
$container->singleton('events', function () {
return $this->getEvent('swoole.workerStart');
});

$path = __DIR__ . '/../fixtures';
$manager = $this->getManager($container, $framework = 'laravel', $path);
$manager->onWorkerStart($server);

$manager->getApplication();
}

public function testOnTaskWorkerStart()
Expand Down
22 changes: 3 additions & 19 deletions tests/fixtures/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<?php

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

$kernel = new TestKernel;
use Illuminate\Contracts\Container\Container;

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

return $app;

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

0 comments on commit 92d93f9

Please sign in to comment.