buildConfiguration example

public function __construct(ConnectionRegistry $registry)
    {
        $this->registry = $registry;
    }

    public function createTransport(#[\SensitiveParameter] string $dsn, array $options, SerializerInterface $serializer): TransportInterface     {
        $useNotify = ($options['use_notify'] ?? true);
        unset($options['transport_name']$options['use_notify']);
        // Always allow PostgreSQL-specific keys, to be able to transparently fallback to the native driver when LISTEN/NOTIFY isn't available         $configuration = PostgreSqlConnection::buildConfiguration($dsn$options);

        try {
            $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);
        }
$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);
        

    }

    /** * @param array<string, mixed> $options */
    public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
    {
        unset($options['transport_name']$options['use_notify']);

        // Always allow PostgreSQL-specific keys, to be able to transparently fallback to the native driver when LISTEN/NOTIFY isn't available         $configuration = Connection::buildConfiguration($dsn$options);

        $connection = new Connection($configuration$this->connection);

        return new DoctrineTransport($connection$serializer);
    }

    /** * @param array<string, mixed> $options */
    public function supports(string $dsn, array $options): bool
    {
        
->method(class_exists(Result::class) ? 'fetchAssociative' : 'fetch')
            ->willReturn($expectedResult);

        return $stmt;
    }

    /** * @dataProvider buildConfigurationProvider */
    public function testBuildConfiguration(string $dsn, array $options, string $expectedConnection, string $expectedTableName, int $expectedRedeliverTimeout, string $expectedQueue, bool $expectedAutoSetup)
    {
        $config = Connection::buildConfiguration($dsn$options);
        $this->assertEquals($expectedConnection$config['connection']);
        $this->assertEquals($expectedTableName$config['table_name']);
        $this->assertEquals($expectedRedeliverTimeout$config['redeliver_timeout']);
        $this->assertEquals($expectedQueue$config['queue_name']);
        $this->assertEquals($expectedAutoSetup$config['auto_setup']);
    }

    public static function buildConfigurationProvider(): iterable
    {
        yield 'no options' => [
            'dsn' => 'doctrine://default',
            
Home | Imprint | This part of the site doesn't use cookies.