Skip to content

Commit

Permalink
Merge pull request php-enqueue#933 from Lctrs/reset-doctrineodm
Browse files Browse the repository at this point in the history
Add a service to reset doctrine/odm identity maps
  • Loading branch information
makasim authored Aug 8, 2019
2 parents 4f5be8e + b4a909c commit 6afffd3
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 1 deletion.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"symfony/framework-bundle": "^3.4|^4",
"empi89/php-amqp-stubs": "*@dev",
"doctrine/doctrine-bundle": "~1.2",
"doctrine/mongodb-odm-bundle": "^3.5",
"alcaeus/mongo-php-adapter": "^1.0",
"kwn/php-rdkafka-stubs": "^1.0.2",
"friendsofphp/php-cs-fixer": "^2"
},
Expand Down Expand Up @@ -112,7 +114,8 @@
"ext-rdkafka": "3.3",
"ext-mongodb": "1.3",
"ext-bcmath": "1",
"ext-mbstring": "1"
"ext-mbstring": "1",
"ext-mongo": "1.6.14"
},
"prefer-stable": true
}
Expand Down
1 change: 1 addition & 0 deletions docs/bundle/config_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enqueue:
extensions:
doctrine_ping_connection_extension: false
doctrine_clear_identity_map_extension: false
doctrine_odm_clear_identity_map_extension: false
reset_services_extension: false
signal_extension: true
reply_extension: true
Expand Down
1 change: 1 addition & 0 deletions pkg/enqueue-bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayNode('extensions')->addDefaultsIfNotSet()->children()
->booleanNode('doctrine_ping_connection_extension')->defaultFalse()->end()
->booleanNode('doctrine_clear_identity_map_extension')->defaultFalse()->end()
->booleanNode('doctrine_odm_clear_identity_map_extension')->defaultFalse()->end()
->booleanNode('reset_services_extension')->defaultFalse()->end()
->booleanNode('signal_extension')->defaultValue(function_exists('pcntl_signal_dispatch'))->end()
->booleanNode('reply_extension')->defaultTrue()->end()
Expand Down
24 changes: 24 additions & 0 deletions pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function load(array $configs, ContainerBuilder $container): void
// extensions
$this->loadDoctrinePingConnectionExtension($config, $container);
$this->loadDoctrineClearIdentityMapExtension($config, $container);
$this->loadDoctrineOdmClearIdentityMapExtension($config, $container);
$this->loadResetServicesExtension($config, $container);
$this->loadSignalExtension($config, $container);
$this->loadReplyExtension($config, $container);
Expand Down Expand Up @@ -249,6 +250,29 @@ private function loadDoctrineClearIdentityMapExtension(array $config, ContainerB
}
}

private function loadDoctrineOdmClearIdentityMapExtension(array $config, ContainerBuilder $container): void
{
$configNames = [];
foreach ($config as $name => $modules) {
if ($modules['extensions']['doctrine_odm_clear_identity_map_extension']) {
$configNames[] = $name;
}
}

if ([] === $configNames) {
return;
}

$extension = $container->register('enqueue.consumption.doctrine_odm_clear_identity_map_extension', DoctrineClearIdentityMapExtension::class)
->addArgument(new Reference('doctrine_mongodb'))
;

foreach ($configNames as $name) {
$extension->addTag('enqueue.consumption_extension', ['client' => $name]);
$extension->addTag('enqueue.transport.consumption_extension', ['transport' => $name]);
}
}

private function loadResetServicesExtension(array $config, ContainerBuilder $container)
{
$configNames = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,49 @@ public function testDoctrineClearIdentityMapExtensionCouldBeEnabled()
], $config);
}

public function testDoctrineOdmClearIdentityMapExtensionShouldBeDisabledByDefault()
{
$configuration = new Configuration(true);

$processor = new Processor();
$config = $processor->processConfiguration($configuration, [[
'default' => [
'transport' => null,
],
]]);

$this->assertArraySubset([
'default' => [
'extensions' => [
'doctrine_odm_clear_identity_map_extension' => false,
],
],
], $config);
}

public function testDoctrineOdmClearIdentityMapExtensionCouldBeEnabled()
{
$configuration = new Configuration(true);

$processor = new Processor();
$config = $processor->processConfiguration($configuration, [[
'default' => [
'transport' => [],
'extensions' => [
'doctrine_odm_clear_identity_map_extension' => true,
],
],
]]);

$this->assertArraySubset([
'default' => [
'extensions' => [
'doctrine_odm_clear_identity_map_extension' => true,
],
],
], $config);
}

public function testResetServicesExtensionShouldBeDisabledByDefault()
{
$configuration = new Configuration(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,42 @@ public function testShouldNotLoadDoctrineClearIdentityMapExtensionServiceIfDisab
self::assertFalse($container->hasDefinition('enqueue.consumption.doctrine_clear_identity_map_extension'));
}

public function testShouldLoadDoctrineOdmClearIdentityMapExtensionServiceIfEnabled()
{
$container = $this->getContainerBuilder(true);

$extension = new EnqueueExtension();

$extension->load([[
'default' => [
'transport' => [],
'extensions' => [
'doctrine_odm_clear_identity_map_extension' => true,
],
],
]], $container);

self::assertTrue($container->hasDefinition('enqueue.consumption.doctrine_odm_clear_identity_map_extension'));
}

public function testShouldNotLoadDoctrineOdmClearIdentityMapExtensionServiceIfDisabled()
{
$container = $this->getContainerBuilder(true);

$extension = new EnqueueExtension();

$extension->load([[
'default' => [
'transport' => [],
'extensions' => [
'doctrine_odm_clear_identity_map_extension' => false,
],
],
]], $container);

self::assertFalse($container->hasDefinition('enqueue.consumption.doctrine_odm_clear_identity_map_extension'));
}

public function testShouldLoadResetServicesExtensionServiceIfEnabled()
{
$container = $this->getContainerBuilder(true);
Expand Down
1 change: 1 addition & 0 deletions pkg/enqueue-bundle/Tests/fix_composer_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
$composerJson = json_decode(file_get_contents(__DIR__.'/../composer.json'), true);

$composerJson['config']['platform']['ext-amqp'] = '1.9.3';
$composerJson['config']['platform']['ext-mongo'] = '1.6.14';

file_put_contents(__DIR__.'/../composer.json', json_encode($composerJson, JSON_PRETTY_PRINT));
2 changes: 2 additions & 0 deletions pkg/enqueue-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"enqueue/async-command": "0.9.x-dev",
"php-amqplib/php-amqplib": "^2.7",
"doctrine/doctrine-bundle": "~1.2",
"doctrine/mongodb-odm-bundle": "^3.5",
"alcaeus/mongo-php-adapter": "^1.0",
"symfony/browser-kit": "^3.4|^4",
"symfony/expression-language": "^3.4|^4"
},
Expand Down

0 comments on commit 6afffd3

Please sign in to comment.