8000 bug #45983 [Messenger] DoctrineTransportFactory works with notify and… · symfony/symfony@23338d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 23338d0

Browse files
committed
bug #45983 [Messenger] DoctrineTransportFactory works with notify and decorated PostgreSQL driver (alamirault)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Messenger] DoctrineTransportFactory works with notify and decorated PostgreSQL driver | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #45835 | License | MIT | Doc PR | This PR allow to use Notify connection with Decorated PostgreSQL driver and not only for `AbstractPostgreSQLDriver` Commits ------- 07c3125 [Messenger] DoctrineTransportFactory works with notify and decorated PostgreSQL driver
2 parents ea6c3a6 + 07c3125 commit 23338d0

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

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

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

14+
use Doctrine\DBAL\Platforms\AbstractPlatform;
15+
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1416
use Doctrine\DBAL\Schema\AbstractSchemaManager;
1517
use Doctrine\DBAL\Schema\SchemaConfig;
1618
use Doctrine\Persistence\ConnectionRegistry;
@@ -22,6 +24,9 @@
2224
use Symfony\Component\Messenger\Exception\TransportException;
2325
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
2426

27+
// Doctrine DBAL 2 compatibility
28+
class_exists(\Doctrine\DBAL\Platforms\PostgreSqlPlatform::class);
29+
2530
class DoctrineTransportFactoryTest extends TestCase
2631
{
2732
public function testSupports()
@@ -39,8 +44,10 @@ public function testCreateTransport()
3944
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
4045
$schemaManager = $this->createMock(AbstractSchemaManager::class);
4146
$schemaConfig = $this->createMock(SchemaConfig::class);
47+
$platform = $this->createMock(AbstractPlatform::class);
4248
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
4349
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
50+
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
4451
$registry = $this->createMock(ConnectionRegistry::class);
4552

4653
$registry->expects($this->once())
@@ -56,6 +63,30 @@ public function testCreateTransport()
5663
);
5764
}
5865

66+
public function testCreateTransportNotifyWithPostgreSQLPlatform()
67+
{
68+
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
69+
$schemaManager = $this->createMock(AbstractSchemaManager::class);
70+
$schemaConfig = $this->createMock(SchemaConfig::class);
71+
$platform = $this->createMock(PostgreSQLPlatform::class);
72+
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
73+
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
74+
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
75+
$registry = $this->createMock(ConnectionRegistry::class);
76+
77+
$registry->expects($this->once())
78+
->method('getConnection')
79+
->willReturn($driverConnection);
80+
81+
$factory = new DoctrineTransportFactory($registry);
82+
$serializer = $this->createMock(SerializerInterface::class);
83+
84+
$this->assertEquals(
85+
new DoctrineTransport(new PostgreSqlConnection(PostgreSqlConnection::buildConfiguration('doctrine://default'), $driverConnection), $serializer),
86+
$factory->createTransport('doctrine://default', [], $serializer)
87+
);
88+
}
89+
5990
public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound()
6091
{
6192
$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->getDatabasePlatform() instanceof PostgreSQLPlatform) {
5252
$connection = new PostgreSqlConnection($configuration, $driverConnection);
5353
} else {
5454
$connection = new Connection($configuration, $driverConnection);

0 commit comments

Comments
 (0)
0