From 07c3125ceff14990f162b4356d112e5e2a8867a6 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sun, 10 Apr 2022 16:44:40 +0200 Subject: [PATCH] [Messenger] DoctrineTransportFactory works with notify and decorated PostgreSQL driver --- .../DoctrineTransportFactoryTest.php | 31 +++++++++++++++++++ .../Transport/DoctrineTransportFactory.php | 4 +-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php index 05b664e70e6ff..54dd7ab153adf 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\SchemaConfig; use Doctrine\Persistence\ConnectionRegistry; @@ -22,6 +24,9 @@ use Symfony\Component\Messenger\Exception\TransportException; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; +// Doctrine DBAL 2 compatibility +class_exists(\Doctrine\DBAL\Platforms\PostgreSqlPlatform::class); + class DoctrineTransportFactoryTest extends TestCase { public function testSupports() @@ -39,8 +44,10 @@ public function testCreateTransport() $driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class); $schemaManager = $this->createMock(AbstractSchemaManager::class); $schemaConfig = $this->createMock(SchemaConfig::class); + $platform = $this->createMock(AbstractPlatform::class); $schemaManager->method('createSchemaConfig')->willReturn($schemaConfig); $driverConnection->method('getSchemaManager')->willReturn($schemaManager); + $driverConnection->method('getDatabasePlatform')->willReturn($platform); $registry = $this->createMock(ConnectionRegistry::class); $registry->expects($this->once()) @@ -56,6 +63,30 @@ public function testCreateTransport() ); } + public function testCreateTransportNotifyWithPostgreSQLPlatform() + { + $driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class); + $schemaManager = $this->createMock(AbstractSchemaManager::class); + $schemaConfig = $this->createMock(SchemaConfig::class); + $platform = $this->createMock(PostgreSQLPlatform::class); + $schemaManager->method('createSchemaConfig')->willReturn($schemaConfig); + $driverConnection->method('getSchemaManager')->willReturn($schemaManager); + $driverConnection->method('getDatabasePlatform')->willReturn($platform); + $registry = $this->createMock(ConnectionRegistry::class); + + $registry->expects($this->once()) + ->method('getConnection') + ->willReturn($driverConnection); + + $factory = new DoctrineTransportFactory($registry); + $serializer = $this->createMock(SerializerInterface::class); + + $this->assertEquals( + new DoctrineTransport(new PostgreSqlConnection(PostgreSqlConnection::buildConfiguration('doctrine://default'), $driverConnection), $serializer), + $factory->createTransport('doctrine://default', [], $serializer) + ); + } + public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound() { $this->expectException(TransportException::class); diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/DoctrineTransportFactory.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/DoctrineTransportFactory.php index 0cda9a35ea6af..f634e5548168f 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/DoctrineTransportFactory.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/DoctrineTransportFactory.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Messenger\Bridge\Doctrine\Transport; -use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\Persistence\ConnectionRegistry; use Symfony\Bridge\Doctrine\RegistryInterface; use Symfony\Component\Messenger\Exception\TransportException; @@ -48,7 +48,7 @@ public function createTransport(string $dsn, array $options, SerializerInterface throw new TransportException(sprintf('Could not find Doctrine connection from Messenger DSN "%s".', $dsn), 0, $e); } - if ($useNotify && $driverConnection->getDriver() instanceof AbstractPostgreSQLDriver) { + if ($useNotify && $driverConnection->getDatabasePlatform() instanceof PostgreSQLPlatform) { $connection = new PostgreSqlConnection($configuration, $driverConnection); } else { $connection = new Connection($configuration, $driverConnection);