Skip to content

Commit

Permalink
tests(kernel): add tests kernel bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Oct 23, 2020
1 parent d5eaf4c commit cf381af
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
24 changes: 20 additions & 4 deletions tests/Kernel/KernelConsoleTest.php
Expand Up @@ -101,6 +101,12 @@ class KernelConsoleTest extends TestCase
* ``` php
* {[\Leevel\Kernel\Utils\Doc::getClassBody(\Tests\Kernel\Commands\Console\Bar::class)]}
* ```
*
* **Tests\Kernel\DemoBootstrapForKernelConsole**
*
* ``` php
* {[\Leevel\Kernel\Utils\Doc::getClassBody(\Tests\Kernel\DemoBootstrapForKernelConsole::class)]}
* ```
* ",
* zh-CN:note="",
* )
Expand All @@ -115,8 +121,10 @@ public function testBaseUse(): void
$kernel = new KernelConsole1($app);
$this->assertInstanceof(IKernelConsole::class, $kernel);
$this->assertInstanceof(IApp::class, $kernel->getApp());

$this->assertSame(0, $kernel->handle());
$kernel->terminate(0);
$this->assertTrue($GLOBALS['DemoBootstrapForKernelConsole']);
unset($GLOBALS['DemoBootstrapForKernelConsole']);
}

protected function createOption(IContainer $container): void
Expand Down Expand Up @@ -145,9 +153,9 @@ protected function createOption(IContainer $container): void

class KernelConsole1 extends KernelConsole
{
public function bootstrap(): void
{
}
protected array $bootstraps = [
DemoBootstrapForKernelConsole::class,
];

protected function getConsoleApplication(): Application
{
Expand Down Expand Up @@ -178,3 +186,11 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
return 0;
}
}

class DemoBootstrapForKernelConsole
{
public function handle(IApp $app): void
{
$GLOBALS['DemoBootstrapForKernelConsole'] = true;
}
}
24 changes: 20 additions & 4 deletions tests/Kernel/KernelTest.php
Expand Up @@ -80,6 +80,12 @@ class KernelTest extends TestCase
* ``` php
* {[\Leevel\Kernel\Utils\Doc::getClassBody(\Tests\Kernel\Kernel1::class)]}
* ```
*
* **Tests\Kernel\DemoBootstrapForKernel**
*
* ``` php
* {[\Leevel\Kernel\Utils\Doc::getClassBody(\Tests\Kernel\DemoBootstrapForKernel::class)]}
* ```
* ",
* zh-CN:note="",
* )
Expand All @@ -100,8 +106,10 @@ public function testBaseUse(bool $debug): void
$kernel = new Kernel1($app, $router);
$this->assertInstanceof(IKernel::class, $kernel);
$this->assertInstanceof(IApp::class, $kernel->getApp());

$this->assertInstanceof(Response::class, $resultResponse = $kernel->handle($request));
$kernel->terminate($request, $resultResponse);
$this->assertTrue($GLOBALS['DemoBootstrapForKernel']);
unset($GLOBALS['DemoBootstrapForKernel']);
}

public function baseUseProvider(): array
Expand Down Expand Up @@ -292,9 +300,9 @@ protected function createRouterWithError(): IRouter

class Kernel1 extends Kernel
{
public function bootstrap(): void
{
}
protected array $bootstraps = [
DemoBootstrapForKernel::class,
];
}

class AppKernel extends Apps
Expand All @@ -316,3 +324,11 @@ public function getDefaultHttpExceptionView(): string
return '';
}
}

class DemoBootstrapForKernel
{
public function handle(IApp $app): void
{
$GLOBALS['DemoBootstrapForKernel'] = true;
}
}

0 comments on commit cf381af

Please sign in to comment.