Skip to content

Commit

Permalink
Add container in the AbstractKernel::create() signature
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed May 16, 2022
1 parent dc1346e commit a032037
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Boot/src/AbstractKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public static function create(
array $directories,
bool $handleErrors = true,
ExceptionHandlerInterface|string|null $exceptionHandler = null,
Container $container = new Container(),
): static {
$container = new Container();
$exceptionHandler ??= ExceptionHandler::class;

if (\is_string($exceptionHandler)) {
Expand All @@ -100,7 +100,7 @@ public static function create(
$exceptionHandler->register();
}

return new static(new Container(), $exceptionHandler, $directories);
return new static($container, $exceptionHandler, $directories);
}

/**
Expand Down
23 changes: 15 additions & 8 deletions tests/Framework/KernelTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
<?php

/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/

declare(strict_types=1);

namespace Spiral\Tests\Framework;

use Spiral\Boot\Environment;
use Spiral\Boot\Exception\BootException;
use Spiral\Config\ConfiguratorInterface;
use Spiral\App\TestApp;
use Spiral\Core\Container;
use stdClass;

class KernelTest extends BaseTest
{
Expand Down Expand Up @@ -45,4 +39,17 @@ public function testNoRootDirectory(): void

TestApp::create([], false)->run();
}

public function testCustomContainer(): void
{
$container = new Container();
$container->bind('foofoo', new stdClass());

$app = TestApp::create([
'root' => __DIR__ . '/../..',
], container: $container);

$this->assertSame($container, $app->getContainer());
$this->assertInstanceOf(stdClass::class, $app->get('foofoo'));
}
}

0 comments on commit a032037

Please sign in to comment.