Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
namespace Ibexa\Bundle\Test\Core\DependencyInjection\CompilerPass;

use Ibexa\Bundle\RepositoryInstaller\Event\Subscriber\BuildSchemaSubscriber;
use Ibexa\Contracts\Core\Test\Persistence\Fixture\FixtureImporter;
use Ibexa\Contracts\DoctrineSchema\Builder\SchemaBuilderInterface;
use Ibexa\Contracts\Test\Core\Bootstrapper\DatabaseSchemaHook;
use Ibexa\Contracts\Test\Core\Bootstrapper\FixtureHook;
use Ibexa\Contracts\Test\Core\Bootstrapper\PurgeIndexAfterFixturesHook;
use Ibexa\Contracts\Test\Core\Bootstrapper\PurgeSearchIndexHook;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand All @@ -30,6 +34,9 @@ final class RemoveUnsatisfiableHooksPass implements CompilerPassInterface
// tables but none of core's
BuildSchemaSubscriber::class,
],
FixtureHook::class => [FixtureImporter::class],
PurgeSearchIndexHook::class => ['ibexa.spi.search'],
PurgeIndexAfterFixturesHook::class => ['ibexa.spi.search'],
];

public function process(ContainerBuilder $container): void
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/Bootstrapper/Bootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

namespace Ibexa\Contracts\Test\Core\Bootstrapper;

use Ibexa\Contracts\Test\Core\IbexaTestKernel;
use LogicException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand Down Expand Up @@ -74,7 +74,7 @@ public function __construct(
public function bootstrap(
?string $kernelClass = null,
array $options = []
): IbexaTestKernel {
): KernelInterface {
$kernel = $this->kernelProvider->getKernel($kernelClass);

$testContainer = self::getService($kernel->getContainer(), 'test.service_container', ContainerInterface::class);
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/Bootstrapper/DatabasePreparer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Ibexa\Contracts\Test\Core\Bootstrapper;

use Ibexa\Contracts\Test\Core\IbexaTestKernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* @internal
Expand All @@ -23,7 +23,7 @@ public function __construct()
$this->consoleCommandRunner = new ConsoleCommandRunner();
}

public function prepareDatabase(IbexaTestKernel $kernel, bool $runSchemaUpdate): void
public function prepareDatabase(KernelInterface $kernel, bool $runSchemaUpdate): void
{
$application = new Application($kernel);
$application->setAutoExit(false);
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/Bootstrapper/DatabasePreparerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Ibexa\Contracts\Test\Core\Bootstrapper;

use Ibexa\Contracts\Test\Core\IbexaTestKernel;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* @experimental
Expand All @@ -22,5 +22,5 @@ interface DatabasePreparerInterface
/**
* @throws \Exception command failures propagate as-is
*/
public function prepareDatabase(IbexaTestKernel $kernel, bool $runSchemaUpdate): void;
public function prepareDatabase(KernelInterface $kernel, bool $runSchemaUpdate): void;
}
10 changes: 5 additions & 5 deletions src/contracts/Bootstrapper/KernelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

namespace Ibexa\Contracts\Test\Core\Bootstrapper;

use Ibexa\Contracts\Test\Core\IbexaTestKernel;
use LogicException;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* @internal
*/
final class KernelProvider implements KernelProviderInterface
{
public function getKernel(?string $kernelClass): IbexaTestKernel
public function getKernel(?string $kernelClass): KernelInterface
{
$kernelClass ??= $_ENV['KERNEL_CLASS'] ?? $_SERVER['KERNEL_CLASS'] ?? null;
if ($kernelClass === null || !is_a($kernelClass, IbexaTestKernel::class, true)) {
if ($kernelClass === null || !is_a($kernelClass, KernelInterface::class, true)) {
throw new LogicException(sprintf(
'The kernel class "%s" must be a subclass of "%s". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class.',
'The kernel class "%s" must implement "%s". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class.',
$kernelClass ?? 'null',
IbexaTestKernel::class,
KernelInterface::class,
));
}

Expand Down
8 changes: 4 additions & 4 deletions src/contracts/Bootstrapper/KernelProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Ibexa\Contracts\Test\Core\Bootstrapper;

use Ibexa\Contracts\Test\Core\IbexaTestKernel;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* @experimental
Expand All @@ -20,8 +20,8 @@
interface KernelProviderInterface
{
/**
* @throws \LogicException if $kernelClass (or its env/server fallback) isn't a valid
* IbexaTestKernel subclass
* @throws \LogicException if $kernelClass (or its env/server fallback) doesn't name a
* bootable {@see KernelInterface} implementation
*/
public function getKernel(?string $kernelClass): IbexaTestKernel;
public function getKernel(?string $kernelClass): KernelInterface;
}
38 changes: 36 additions & 2 deletions tests/contracts/Bootstrapper/KernelProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use LogicException;
use PHPUnit\Framework\TestCase;
use stdClass;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* @covers \Ibexa\Contracts\Test\Core\Bootstrapper\KernelProvider
Expand Down Expand Up @@ -52,8 +54,8 @@ protected function tearDown(): void
}

/**
* @testWith [null, "The kernel class \"null\" must be a subclass of \"Ibexa\\Contracts\\Test\\Core\\IbexaTestKernel\". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class."]
* ["stdClass", "The kernel class \"stdClass\" must be a subclass of \"Ibexa\\Contracts\\Test\\Core\\IbexaTestKernel\". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class."]
* @testWith [null, "The kernel class \"null\" must implement \"Symfony\\Component\\HttpKernel\\KernelInterface\". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class."]
* ["stdClass", "The kernel class \"stdClass\" must implement \"Symfony\\Component\\HttpKernel\\KernelInterface\". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class."]
*/
public function testThrowsWhenKernelClassIsInvalid(?string $kernelClass, string $exceptionMessage): void
{
Expand Down Expand Up @@ -91,6 +93,14 @@ public function testArgumentTakesPrecedenceOverEnvAndServerFallbacks(): void
self::assertInstanceOf(NoopBootTestKernel::class, $kernel);
}

public function testAcceptsAnyKernelInterfaceImplementation(): void
{
$kernel = (new KernelProvider())->getKernel(NoopBootPlainKernel::class);

self::assertInstanceOf(NoopBootPlainKernel::class, $kernel);
self::assertTrue($kernel->didBoot);
}

public function testBootsTheReturnedKernel(): void
{
$kernel = (new KernelProvider())->getKernel(NoopBootTestKernel::class);
Expand All @@ -100,6 +110,30 @@ public function testBootsTheReturnedKernel(): void
}
}

final class NoopBootPlainKernel extends Kernel
{
public bool $didBoot = false;

public function __construct()
{
parent::__construct('test', true);
}

public function boot(): void
{
$this->didBoot = true;
}

public function registerBundles(): iterable
{
return [];
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
}
}

final class NoopBootTestKernel extends IbexaTestKernel
{
public bool $didBoot = false;
Expand Down