diff --git a/src/bundle/DependencyInjection/CompilerPass/RemoveUnsatisfiableHooksPass.php b/src/bundle/DependencyInjection/CompilerPass/RemoveUnsatisfiableHooksPass.php index e76fd70..1c4f0d8 100644 --- a/src/bundle/DependencyInjection/CompilerPass/RemoveUnsatisfiableHooksPass.php +++ b/src/bundle/DependencyInjection/CompilerPass/RemoveUnsatisfiableHooksPass.php @@ -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; @@ -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 diff --git a/src/contracts/Bootstrapper/Bootstrapper.php b/src/contracts/Bootstrapper/Bootstrapper.php index f73705d..e6b3c13 100644 --- a/src/contracts/Bootstrapper/Bootstrapper.php +++ b/src/contracts/Bootstrapper/Bootstrapper.php @@ -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; @@ -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); diff --git a/src/contracts/Bootstrapper/DatabasePreparer.php b/src/contracts/Bootstrapper/DatabasePreparer.php index 6c70a61..0a1ceb8 100644 --- a/src/contracts/Bootstrapper/DatabasePreparer.php +++ b/src/contracts/Bootstrapper/DatabasePreparer.php @@ -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 @@ -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); diff --git a/src/contracts/Bootstrapper/DatabasePreparerInterface.php b/src/contracts/Bootstrapper/DatabasePreparerInterface.php index be1c269..2ffe0f0 100644 --- a/src/contracts/Bootstrapper/DatabasePreparerInterface.php +++ b/src/contracts/Bootstrapper/DatabasePreparerInterface.php @@ -8,7 +8,7 @@ namespace Ibexa\Contracts\Test\Core\Bootstrapper; -use Ibexa\Contracts\Test\Core\IbexaTestKernel; +use Symfony\Component\HttpKernel\KernelInterface; /** * @experimental @@ -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; } diff --git a/src/contracts/Bootstrapper/KernelProvider.php b/src/contracts/Bootstrapper/KernelProvider.php index 78c6d7e..a32338a 100644 --- a/src/contracts/Bootstrapper/KernelProvider.php +++ b/src/contracts/Bootstrapper/KernelProvider.php @@ -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, )); } diff --git a/src/contracts/Bootstrapper/KernelProviderInterface.php b/src/contracts/Bootstrapper/KernelProviderInterface.php index abf20a5..d692fe1 100644 --- a/src/contracts/Bootstrapper/KernelProviderInterface.php +++ b/src/contracts/Bootstrapper/KernelProviderInterface.php @@ -8,7 +8,7 @@ namespace Ibexa\Contracts\Test\Core\Bootstrapper; -use Ibexa\Contracts\Test\Core\IbexaTestKernel; +use Symfony\Component\HttpKernel\KernelInterface; /** * @experimental @@ -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; } diff --git a/tests/contracts/Bootstrapper/KernelProviderTest.php b/tests/contracts/Bootstrapper/KernelProviderTest.php index 9eb1682..249cc84 100644 --- a/tests/contracts/Bootstrapper/KernelProviderTest.php +++ b/tests/contracts/Bootstrapper/KernelProviderTest.php @@ -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 @@ -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 { @@ -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); @@ -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;