8000 [Messenger] DoctrineTransportFactory works with notify and decorated PostgreSQL driver by alamirault · Pull Request #45983 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] DoctrineTransportFactory works wit 8000 h notify and decorated PostgreSQL driver #45983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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())
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
0