Skip to content

Commit

Permalink
[Tests] Added IbexaTestKernel
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Oct 26, 2023
1 parent e71c3bc commit ebb530c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 31 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
},
"require-dev": {
"symfony/proxy-manager-bridge": "^5.4",
"symfony/phpunit-bridge": "^5.4",
"ibexa/doctrine-schema": "~4.6.0@dev",
"ibexa/test-core": "^4.6.x-dev",
"phpunit/phpunit": "^8.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"ibexa/code-style": "^1.0",
Expand All @@ -50,6 +52,7 @@
"psr-4": {
"Ibexa\\Tests\\Bundle\\Solr\\": "tests/bundle/",
"Ibexa\\Tests\\Solr\\": "tests/lib/",
"Ibexa\\Tests\\Integration\\Solr\\": "tests/integration/",
"Ibexa\\Tests\\Integration\\Core\\": "vendor/ibexa/core/tests/integration/Core/",
"Ibexa\\Tests\\Core\\": "vendor/ibexa/core/tests/lib/",
"Ibexa\\Tests\\Bundle\\Core\\": "vendor/ibexa/core/tests/bundle/",
Expand All @@ -63,7 +66,7 @@
"test": "phpunit --bootstrap tests/bootstrap.php -c phpunit.xml",
"test-integration-solr": [
"Composer\\Config::disableProcessTimeout",
"phpunit --bootstrap tests/bootstrap.php -c vendor/ibexa/core/phpunit-integration-legacy-solr.xml"
"phpunit vendor/ibexa/core/tests/integration/Core/Repository/SearchServiceImageTest.php --bootstrap tests/bootstrap.php -c vendor/ibexa/core/phpunit-integration-legacy-solr.xml"
],
"phpstan": "phpstan analyse"
},
Expand Down
42 changes: 42 additions & 0 deletions tests/integration/IbexaTestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\Solr;

use Ibexa\Bundle\Solr\IbexaSolrBundle;
use Ibexa\Contracts\Core\Search\Handler;
use Ibexa\Contracts\Test\Core\IbexaTestKernel as BaseIbexaTestKernel;
use Ibexa\Solr\Handler as SolrHandler;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class IbexaTestKernel extends BaseIbexaTestKernel
{
public function registerBundles(): iterable
{
yield from parent::registerBundles();

yield new IbexaSolrBundle();
}

protected static function getExposedServicesById(): iterable
{
yield from parent::getExposedServicesById();

yield SolrHandler::class => Handler::class;
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);

$loader->load(static function (ContainerBuilder $container): void {
(new SolrTestContainerBuilder())->loadSolrSettings($container);
});
}
}
60 changes: 60 additions & 0 deletions tests/integration/SolrTestContainerBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\Solr;

use Ibexa\Tests\Integration\Core\Repository\SearchServiceTranslationLanguageFallbackTest;
use RuntimeException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

/**
* @internal
*/
final class SolrTestContainerBuilder
{
public const CONFIGURATION_FILES_MAP = [
SearchServiceTranslationLanguageFallbackTest::SETUP_DEDICATED => 'multicore_dedicated.yml',
SearchServiceTranslationLanguageFallbackTest::SETUP_SHARED => 'multicore_shared.yml',
SearchServiceTranslationLanguageFallbackTest::SETUP_SINGLE => 'single_core.yml',
SearchServiceTranslationLanguageFallbackTest::SETUP_CLOUD => 'cloud.yml',
];

public function loadSolrSettings(ContainerBuilder $containerBuilder): void
{
$containerBuilder->setParameter('test.ibexa.solr.host', getenv('SOLR_HOST') ?: 'localhost');

$settingsPath = dirname(__DIR__, 2) . '/src/lib/Resources/config/container/';
$testSettingsPath = dirname(__DIR__) . '/lib/Resources/config/';

$solrLoader = new YamlFileLoader($containerBuilder, new FileLocator($settingsPath));
$solrLoader->load('solr.yml');

$testConfigurationFile = $this->getTestConfigurationFile();
$solrTestLoader = new YamlFileLoader($containerBuilder, new FileLocator($testSettingsPath));
$solrTestLoader->load($testConfigurationFile);

$containerBuilder->addResource(new FileResource($testSettingsPath . $testConfigurationFile));
}

public function getTestConfigurationFile(): string
{
$isSolrCloud = getenv('SOLR_CLOUD') === 'yes';
$coresSetup = $isSolrCloud
? SearchServiceTranslationLanguageFallbackTest::SETUP_CLOUD
: getenv('CORES_SETUP');

if (!isset(self::CONFIGURATION_FILES_MAP[$coresSetup])) {
throw new RuntimeException("Backend cores setup '{$coresSetup}' is not handled");
}

return self::CONFIGURATION_FILES_MAP[$coresSetup];
}
}
43 changes: 13 additions & 30 deletions tests/lib/SetupFactory/LegacySetupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
use Ibexa\Solr\Container\Compiler;
use Ibexa\Solr\Gateway\UpdateSerializerInterface;
use Ibexa\Solr\Handler as SolrSearchHandler;
use Ibexa\Tests\Integration\Core\Repository\SearchServiceTranslationLanguageFallbackTest;
use RuntimeException;
use Symfony\Component\Config\FileLocator;
use Ibexa\Tests\Integration\Solr\SolrTestContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;

Expand All @@ -33,12 +30,16 @@
*/
class LegacySetupFactory extends CoreLegacySetupFactory
{
public const CONFIGURATION_FILES_MAP = [
SearchServiceTranslationLanguageFallbackTest::SETUP_DEDICATED => 'multicore_dedicated.yml',
SearchServiceTranslationLanguageFallbackTest::SETUP_SHARED => 'multicore_shared.yml',
SearchServiceTranslationLanguageFallbackTest::SETUP_SINGLE => 'single_core.yml',
SearchServiceTranslationLanguageFallbackTest::SETUP_CLOUD => 'cloud.yml',
];
public const CONFIGURATION_FILES_MAP = SolrTestContainerBuilder::CONFIGURATION_FILES_MAP;

private SolrTestContainerBuilder $containerBuilder;

public function __construct()
{
parent::__construct();

$this->containerBuilder = new SolrTestContainerBuilder();
}

/**
* Returns a configured repository for testing.
Expand Down Expand Up @@ -71,16 +72,7 @@ protected function externalBuildContainer(ContainerBuilder $containerBuilder): v

protected function loadSolrSettings(ContainerBuilder $containerBuilder): void
{
$containerBuilder->setParameter('test.ibexa.solr.host', getenv('SOLR_HOST') ?: 'localhost');

$settingsPath = realpath(__DIR__ . '/../../../src/lib/Resources/config/container/');
$testSettingsPath = realpath(__DIR__ . '/../Resources/config/');

$solrLoader = new YamlFileLoader($containerBuilder, new FileLocator($settingsPath));
$solrLoader->load('solr.yml');

$solrTestLoader = new YamlFileLoader($containerBuilder, new FileLocator($testSettingsPath));
$solrTestLoader->load($this->getTestConfigurationFile());
$this->containerBuilder->loadSolrSettings($containerBuilder);

$containerBuilder->addCompilerPass(new Compiler\FieldMapperPass\BlockFieldMapperPass());
$containerBuilder->addCompilerPass(new Compiler\FieldMapperPass\BlockTranslationFieldMapperPass());
Expand Down Expand Up @@ -152,16 +144,7 @@ protected function indexAll(): void

protected function getTestConfigurationFile(): string
{
$isSolrCloud = getenv('SOLR_CLOUD') === 'yes';
$coresSetup = $isSolrCloud
? SearchServiceTranslationLanguageFallbackTest::SETUP_CLOUD
: getenv('CORES_SETUP');

if (!isset(self::CONFIGURATION_FILES_MAP[$coresSetup])) {
throw new RuntimeException("Backend cores setup '{$coresSetup}' is not handled");
}

return self::CONFIGURATION_FILES_MAP[$coresSetup];
return $this->containerBuilder->getTestConfigurationFile();
}

private function configureSymfonyHttpClient(ContainerBuilder $containerBuilder): void
Expand Down

0 comments on commit ebb530c

Please sign in to comment.