Skip to content

Commit

Permalink
Merge pull request #1043 from weaverryan/enable-messenger-ping-listener
Browse files Browse the repository at this point in the history
Adding support for DoctrineClearEntityManagerWorkerSubscriber
  • Loading branch information
alcaeus authored Nov 5, 2019
2 parents 2d64753 + 21846c4 commit 0d20a98
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\ORM\Version;
use LogicException;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
Expand Down Expand Up @@ -878,6 +879,10 @@ private function loadMessengerServices(ContainerBuilder $container) : void
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('messenger.xml');

if (! class_exists(DoctrineClearEntityManagerWorkerSubscriber::class)) {
$container->removeDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager');
}

if (! class_exists(DoctrineTransportFactory::class)) {
return;
}
Expand Down
13 changes: 5 additions & 8 deletions Resources/config/messenger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
<argument type="service" id="doctrine" />
</service>

<!--
The following service isn't prefixed by the "doctrine.orm" namespace in order for end-users to just use
the "doctrine_clear_entity_manager" shortcut in message buses middleware config
-->
<service id="messenger.middleware.doctrine_clear_entity_manager" class="Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerMiddleware" abstract="true" public="false">
<argument type="service" id="doctrine" />
</service>

<!--
The following service isn't prefixed by the "doctrine.orm" namespace in order for end-users to just use
the "doctrine_ping_connection" shortcut in message buses middleware config
Expand All @@ -43,5 +35,10 @@
<service id="messenger.transport.doctrine.factory" class="Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory" public="false">
<argument type="service" id="doctrine" />
</service>

<service id="doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager" class="Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber" public="false">
<tag name="kernel.event_subscriber" />
<argument type="service" id="doctrine" />
</service>
</services>
</container>
10 changes: 8 additions & 2 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
Expand Down Expand Up @@ -668,12 +669,17 @@ public function testMessengerIntegration()

$this->assertNotNull($middlewarePrototype = $container->getDefinition('messenger.middleware.doctrine_transaction'));
$this->assertCount(1, $middlewarePrototype->getArguments());
$this->assertNotNull($middlewarePrototype = $container->getDefinition('messenger.middleware.doctrine_clear_entity_manager'));
$this->assertCount(1, $middlewarePrototype->getArguments());
$this->assertNotNull($middlewarePrototype = $container->getDefinition('messenger.middleware.doctrine_ping_connection'));
$this->assertCount(1, $middlewarePrototype->getArguments());
$this->assertNotNull($middlewarePrototype = $container->getDefinition('messenger.middleware.doctrine_close_connection'));
$this->assertCount(1, $middlewarePrototype->getArguments());

if (class_exists(DoctrineClearEntityManagerWorkerSubscriber::class)) {
$this->assertNotNull($subscriber = $container->getDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager'));
$this->assertCount(1, $subscriber->getArguments());
} else {
$this->assertFalse($container->hasDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager'));
}
}

/**
Expand Down

0 comments on commit 0d20a98

Please sign in to comment.