DoctrineTransport example

$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 Connection(PostgreSqlConnection::buildConfiguration('doctrine://default')$driverConnection)$serializer),
            $factory->createTransport('doctrine://default', []$serializer)
        );
    }

    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);
        
->method('configureSchema')
            ->with($schema$dbalConnectionstatic fn () => true);

        $transport->configureSchema($schema$dbalConnectionstatic fn () => true);
    }

    private function getTransport(SerializerInterface $serializer = null, Connection $connection = null): DoctrineTransport
    {
        $serializer ??= $this->createMock(SerializerInterface::class);
        $connection ??= $this->createMock(Connection::class);

        return new DoctrineTransport($connection$serializer);
    }
}
$driverConnection = $this->registry->getConnection($configuration['connection']);
        } catch (\InvalidArgumentException $e) {
            throw new TransportException('Could not find Doctrine connection from Messenger DSN.', 0, $e);
        }

        if ($useNotify && $driverConnection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
            $connection = new PostgreSqlConnection($configuration$driverConnection);
        } else {
            $connection = new Connection($configuration$driverConnection);
        }

        return new DoctrineTransport($connection$serializer);
    }

    public function supports(#[\SensitiveParameter] string $dsn, array $options): bool     {
        return str_starts_with($dsn, 'doctrine://');
    }
}
Home | Imprint | This part of the site doesn't use cookies.