N°7870 Prerequisites to test portal services (instantiate a symfony service)

This commit is contained in:
Romain Quetiez
2024-10-02 17:01:06 +02:00
parent c54909f2a3
commit 7a4d29d561
21 changed files with 1233 additions and 17 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Sources\Controller;
use Combodo\iTop\Portal\Controller\AggregatePageBrickController;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
class BootSymfonyKernelTest extends ItopDataTestCase
{
public function testInstantiateServiceWithAnExplicitCallToBootTheKernel()
{
$this->SetKernelClass(\Combodo\iTop\Portal\Kernel::class);
self::bootKernel();
$controller = static::getContainer()->get(AggregatePageBrickController::class);
$this->assertInstanceOf(AggregatePageBrickController::class, $controller);
}
public function testInstantiateServiceWithAnAutomaticKernelBoot()
{
$this->SetKernelClass(\Combodo\iTop\Portal\Kernel::class);
$controller = static::getContainer()->get(AggregatePageBrickController::class);
$this->assertInstanceOf(AggregatePageBrickController::class, $controller);
}
public function testUnspecifiedKernelClassThrowsAnException()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('static::SetKernelClass() must be called before booting the kernel');
static::getContainer();
}
public function testTwoDifferentKernelsCanBeStartedConsecutively()
{
self::markTestSkipped('This test is still failing: the second kernel container does not find the requested service');
$this->SetKernelClass(\Combodo\iTop\Kernel::class);
self::bootKernel();
$this->SetKernelClass(\Combodo\iTop\Portal\Kernel::class);
self::bootKernel();
$controller = static::getContainer()->get(AggregatePageBrickController::class);
$this->assertInstanceOf(AggregatePageBrickController::class, $controller);
}
}