-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Elasticsearch Fixtures (#6)
* Introduce Elasticsearch Fixtures * Update tests and readme * Add final keyword * Update composer * Provide to ElasticSearchExecutor & update tests * Update readme * Define data-fixtures package dependency version * Address code review * Apply Code Standards * Format config * Update parameters.yml
- Loading branch information
1 parent
0f2c3a3
commit 12f9ac6
Showing
28 changed files
with
673 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/DependencyInjection/Compiler/ElasticSearchCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Kununu\TestingBundle\DependencyInjection\Compiler; | ||
|
||
use Elasticsearch\Client; | ||
use Kununu\DataFixtures\Executor\ElasticSearchExecutor; | ||
use Kununu\DataFixtures\Loader\ElasticSearchFixturesLoader; | ||
use Kununu\DataFixtures\Purger\ElasticSearchPurger; | ||
use Kununu\TestingBundle\Service\Orchestrator; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
final class ElasticSearchCompilerPass implements CompilerPassInterface | ||
{ | ||
private const SERVICE_PREFIX = 'kununu_testing.orchestrator.elastic_search'; | ||
|
||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$container->hasParameter('kununu_testing.elastic_search')) { | ||
return; | ||
} | ||
|
||
$indexes = $container->getParameter('kununu_testing.elastic_search'); | ||
|
||
foreach ($indexes as $alias => $config) { | ||
$this->buildElasticSearchOrchestrator($container, $alias, $config['index_name'], $config['service']); | ||
} | ||
} | ||
|
||
private function buildElasticSearchOrchestrator(ContainerBuilder $container, string $alias, string $indexName, string $id): void | ||
{ | ||
/** @var Client $client */ | ||
$client = new Reference($id); | ||
|
||
// Purger Definition | ||
$purgerId = sprintf('%s.%s.purger', self::SERVICE_PREFIX, $alias); | ||
$purgerDefinition = new Definition(ElasticSearchPurger::class, [$client, $indexName]); | ||
$container->setDefinition($purgerId, $purgerDefinition); | ||
|
||
// Executor Definition | ||
$executorId = sprintf('%s.%s.executor', self::SERVICE_PREFIX, $alias); | ||
$executorDefinition = new Definition(ElasticSearchExecutor::class, [$client, $indexName, new Reference($purgerId)]); | ||
$container->setDefinition($executorId, $executorDefinition); | ||
|
||
// Loader definition | ||
$loaderId = sprintf('%s.%s.loader', self::SERVICE_PREFIX, $alias); | ||
$loaderDefinition = new Definition(ElasticSearchFixturesLoader::class); | ||
$container->setDefinition($loaderId, $loaderDefinition); | ||
|
||
$connectionOrchestratorDefinition = new Definition( | ||
Orchestrator::class, | ||
[ | ||
new Reference($executorId), | ||
new Reference($purgerId), | ||
new Reference($loaderId), | ||
] | ||
); | ||
$connectionOrchestratorDefinition->setPublic(true); | ||
|
||
$container->setDefinition(sprintf('%s.%s', self::SERVICE_PREFIX, $alias), $connectionOrchestratorDefinition); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Kununu\TestingBundle\Tests\App\ElasticSearch; | ||
|
||
use Elasticsearch\Client; | ||
use Elasticsearch\ClientBuilder; | ||
|
||
final class ClientFactory | ||
{ | ||
public static function getInstance(array $hosts): Client | ||
{ | ||
return ClientBuilder::create() | ||
->setHosts($hosts) | ||
->build(); | ||
} | ||
} |
Oops, something went wrong.