Copied!

IbexaTestKernel

IbexaTestKernel.php : 73
Extends Kernel
Implements IbexaTestKernelInterface
Tags
Experimental

Baseline test kernel that dependent packages can extend for their integration tests.

Configuring the kernel

It automatically exposes all Repository-based services for consumption in tests (marking them as public prevents them from being removed from test container). A minimal configuration Symfony framework configuration is provided, along with Doctrine connection.

To supply a different configuration, extend IbexaTestKernel::loadConfiguration() method.

You can supply your own services (which is something you probably want) by extending IbexaTestKernel::loadServices().

If you need even more control over how the container is built you can do that by extending the IbexaTestKernel::registerContainerConfiguration().

Adding bundles

Bundles can be added by extending IbexaTestKernel::registerBundles() method (just like in any Kernel).

Exposing your services

To add services to the test Kernel and make them available in tests via IbexaKernelTestCase::getServiceByClassName(), you'll need to extend IbexaTestKernel::getExposedServicesByClass() and / or IbexaTestKernel::getExposedServicesById() method.

IbexaTestKernel::getExposedServicesByClass() is a simpler variant provided for services that are registered in service container using their FQCN.

IbexaTestKernel::getExposedServicesById() is useful if your service is not registered as it's FQCN (for example, if you have multiple services for the same class / interface).

If don't need the repository services (or not all), you can replace the IbexaTestKernel::EXPOSED_SERVICES_BY_CLASS and IbexaTestKernel::EXPOSED_SERVICES_BY_ID consts in extending class, without changing the methods above.

Constants

protectedEXPOSED_SERVICES_BY_CLASS

IbexaTestKernel.php : 78
protected iterable<string|int, class-string> EXPOSED_SERVICES_BY_CLASS = [\Ibexa\Contracts\Core\Persistence\TransactionHandler::class, \Doctrine\DBAL\Connection::class, \Ibexa\Contracts\Core\Repository\Repository::class, \Ibexa\Contracts\Core\Repository\ContentService::class, \Ibexa\Contracts\Core\Repository\ContentTypeService::class, \Ibexa\Contracts\Core\Repository\LanguageService::class, \Ibexa\Contracts\Core\Repository\LocationService::class, \Ibexa\Contracts\Core\Repository\ObjectStateService::class, \Ibexa\Contracts\Core\Repository\PermissionResolver::class, \Ibexa\Contracts\Core\Repository\RoleService::class, \Ibexa\Contracts\Core\Repository\SearchService::class, \Ibexa\Contracts\Core\Repository\SectionService::class, \Ibexa\Contracts\Core\Repository\UserService::class, \Ibexa\Contracts\Core\Repository\TokenService::class, \Ibexa\Contracts\Core\Repository\URLAliasService::class, \Ibexa\Contracts\Core\Repository\BookmarkService::class, \Ibexa\Contracts\Core\Persistence\Handler::class]

protectedEXPOSED_SERVICES_BY_ID

IbexaTestKernel.php : 101
protected iterable<string, class-string> EXPOSED_SERVICES_BY_ID = []

Methods

publicgetAliasServiceId()

IbexaTestKernel.php : 106
public static getAliasServiceId(string $id) : string

Parameters

Name Type Default value Description
$id string - -

Return values

string

a service ID that service aliases will be registered as

publicgetBuildDir()

IbexaTestKernel.php : 132
public getBuildDir() : string

Return values

string

publicgetCacheDir()

IbexaTestKernel.php : 127
public getCacheDir() : string

Return values

string

publicgetFixtures()

IbexaTestKernel.php : 122
public getFixtures() : iterable<string|int, Fixture>

Return values

iterable<string|int, Fixture>

publicgetSchemaFiles()

IbexaTestKernel.php : 114
public getSchemaFiles() : iterable<string|int, string>

Return values

iterable<string|int, string>

publicregisterBundles()

IbexaTestKernel.php : 137
public registerBundles() : iterable<string|int, mixed>

Return values

iterable<string|int, mixed>

publicregisterContainerConfiguration()

IbexaTestKernel.php : 153
public registerContainerConfiguration(LoaderInterface $loader) : void

Parameters

Name Type Default value Description
$loader LoaderInterface - -
Tags
Throws
Exception

protectedaddSyntheticService()

IbexaTestKernel.php : 280

Creates synthetic services in container, allowing compilation of container when some services are missing.

protected static addSyntheticService(ContainerBuilder $container, string $class[, string|null $id = null ]) : void

Additionally, those services can be replaced with mock implementations at runtime, allowing integration testing.

You can set them up in KernelTestCase by calling self::getContainer()->set($id, $this->createMock($class));

Parameters

Name Type Default value Description
$container ContainerBuilder - -
$class string - -
$id string|null null -

protectedgetExposedServicesByClass()

IbexaTestKernel.php : 200
protected static getExposedServicesByClass() : iterable<string|int, class-string>

Return values

iterable<string|int, class-string>

protectedgetExposedServicesById()

IbexaTestKernel.php : 208
protected static getExposedServicesById() : iterable<string, class-string>

Return values

iterable<string, class-string>

protectedloadConfiguration()

IbexaTestKernel.php : 173
protected loadConfiguration(LoaderInterface $loader) : void

Parameters

Name Type Default value Description
$loader LoaderInterface - -
Tags
Throws
Exception

protectedloadSecurity()

IbexaTestKernel.php : 192
protected loadSecurity(LoaderInterface $loader) : void

Parameters

Name Type Default value Description
$loader LoaderInterface - -
Tags
Throws
Exception

protectedloadServices()

IbexaTestKernel.php : 184
protected loadServices(LoaderInterface $loader) : void

Parameters

Name Type Default value Description
$loader LoaderInterface - -
Tags
Throws
Exception