8000 [Messenger] DoctrineTransportFactory works with notify and decorated … · symfony/symfony@daae218 · GitHub
[go: up one dir, main page]

Skip to content

Commit daae218

Browse files
committed
[Messenger] DoctrineTransportFactory works with notify and decorated PostgreSQL driver
1 parent ea6c3a6 commit daae218

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
1313

14+
use Doctrine\DBAL\Driver;
15+
use Doctrine\DBAL\Platforms\AbstractPlatform;
16+
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1417
use Doctrine\DBAL\Schema\AbstractSchemaManager;
1518
use Doctrine\DBAL\Schema\SchemaConfig;
1619
use Doctrine\Persistence\ConnectionRegistry;
@@ -22,6 +25,9 @@
2225
use Symfony\Component\Messenger\Exception\TransportException;
2326
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
2427

28+
// Doctrine DBAL 2 compatibility
29+
class_exists(\Doctrine\DBAL\Platforms\PostgreSqlPlatform::class);
30+
2531
class DoctrineTransportFactoryTest extends TestCase
2632
{
2733
public function testSupports()
@@ -40,7 +46,15 @@ public function testCreateTransport()
4046
$schemaManager = $this->createMock(AbstractSchemaManager::class);
4147
$schemaConfig = $this->createMock(SchemaConfig::class);
4248
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
49+
50+
$platform = $this->createMock(AbstractPlatform::class);
51+
$driver = $this->createMock(Driver::class);
52+
$driver->expects($this->once())
53+
->method('getDatabasePlatform')
54+
->willReturn($platform);
55+
4356
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
57+
$driverConnection->method('getDriver')->willReturn($driver);
4458
$registry = $this->createMock(ConnectionRegistry::class);
4559

4660
$registry->expects($this->once())
@@ -56,6 +70,36 @@ public function testCreateTransport()
5670
);
5771
}
5872

73+
public function testCreateTransportNotifyWithPostgreSQLPlatform()
74+
{
75+
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
76+
$schemaManager = $this->createMock(AbstractSchemaManager::class);
77+
$schemaConfig = $this->createMock(SchemaConfig::class);
78+
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
79+
80+
$platform = $this->createMock(PostgreSQLPlatform::class);
81+
$driver = $this->createMock(Driver::class);
82+
$driver->expects($this->once())
83+
->method('getDatabasePlatform')
84+
->willReturn($platform);
85+
86+
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
87+
$driverConnection->method('getDriver')->willReturn($driver);
88+
$registry = $this->createMock(ConnectionRegistry::class);
89+
90+
$registry->expects($this->once())
91+
->method('getConnection')
92+
->willReturn($driverConnection);
93+
94+
$factory = new DoctrineTransportFactory($registry);
95+
$serializer = $this->createMock(SerializerInterface::class);
96+
97+
$this->assertEquals(
98+
new DoctrineTransport(new PostgreSqlConnection(PostgreSqlConnection::buildConfiguration('doctrine://default'), $driverConnection), $serializer),
99+
$factory->createTransport('doctrine://default', [], $serializer)
100+
);
101+
}
102+
59103
public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound()
60104
{
61105
$this->expectException(TransportException::class);

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/DoctrineTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Messenger\Bridge\Doctrine\Transport;
1313

14-
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
14+
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1515
use Doctrine\Persistence\ConnectionRegistry;
1616
use Symfony\Bridge\Doctrine\RegistryInterface;
1717
use Symfony\Component\Messenger\Exception\TransportException;
@@ -48,7 +48,7 @@ public function createTransport(string $dsn, array $options, SerializerInterface
4848
throw new TransportException(sprintf('Could not find Doctrine connection from Messenger DSN "%s".', $dsn), 0, $e);
4949
}
5050

51-
if ($useNotify && $driverConnection->getDriver() instanceof AbstractPostgreSQLDriver) {
51+
if ($useNotify && $driverConnection->getDriver()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
5252
$connection = new PostgreSqlConnection($configuration, $driverConnection);
5353
} else {
5454
$connection = new Connection($configuration, $driverConnection);

0 commit comments

Comments
 (0)
0