foundation/tests/Unit/Core/Application/ApplicationTest.php
2025-06-13 18:29:55 +02:00

61 lines
No EOL
2.1 KiB
PHP

<?php
declare(strict_types = 1);
namespace Foundation\Tests\Unit\Core\Application;
use Foundation\Core\Application\Application;
use Foundation\Core\Application\Bootstrapper\BootstrapperInterface;
use Foundation\Core\Application\Kernel\HttpKernel;
use Foundation\Core\DependencyInjection\InflectableContainer;
use PHPUnit\Framework\TestCase;
class ApplicationTest extends TestCase
{
private InflectableContainer $container;
private Application $application;
protected function setUp(): void {
$this->container = $this->createMock(InflectableContainer::class);
$this->application = new Application($this->container);
}
public function testCallsAllBootstrappersInOrder(): void {
$bootstrapper1 = $this->createMock(BootstrapperInterface::class);
$bootstrapper2 = $this->createMock(BootstrapperInterface::class);
$callOrder = [];
$bootstrapper1->expects(self::once())->method('bootstrap')->with($this->container)->willReturnCallback(
function () use (&$callOrder): void {
$callOrder[] = 'bootstrapper1';
},
);
$bootstrapper2->expects(self::once())->method('bootstrap')->with($this->container)->willReturnCallback(
function () use (&$callOrder): void {
$callOrder[] = 'bootstrapper2';
},
);
$this->application->addBootstrapper($bootstrapper1);
$this->application->addBootstrapper($bootstrapper2);
$this->application->bootstrap();
self::assertSame(['bootstrapper1', 'bootstrapper2'], $callOrder);
}
public function testStartsHttpKernel(): void {
$httpKernel = $this->createMock(HttpKernel::class);
$this->container->expects(self::once())->method('get')->with(HttpKernel::class)->willReturn($httpKernel);
$httpKernel->expects(self::once())->method('handle');
$this->application->run();
}
public function testGetContainerReturnsInjectedContainer(): void {
self::assertSame($this->container, $this->application->getContainer());
}
}