File tree 2 files changed +53
-0
lines changed
2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -64,9 +64,17 @@ private function constructConnectionString(
64
64
#[SensitiveParameter]
65
65
array $ params
66
66
): string {
67
+ // pg_connect used by Doctrine DBAL does not support [...] notation but requires the host address in plain form like `aa:bb:99...`
68
+ $ matches = [];
69
+ if (preg_match ('/^\[(.+)\]$/ ' , $ params ['host ' ] ?? '' , $ matches )) {
70
+ $ params ['hostaddr ' ] = $ matches [1 ];
71
+ unset($ params ['host ' ]);
72
+ }
73
+
67
74
$ components = array_filter (
68
75
[
69
76
'host ' => $ params ['host ' ] ?? null ,
77
+ 'hostaddr ' => $ params ['hostaddr ' ] ?? null ,
70
78
'port ' => $ params ['port ' ] ?? null ,
71
79
'dbname ' => $ params ['dbname ' ] ?? 'postgres ' ,
72
80
'user ' => $ params ['user ' ] ?? null ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Doctrine \DBAL \Tests \Driver \PgSQL ;
6
+
7
+ use Doctrine \DBAL \Driver as DriverInterface ;
8
+ use Doctrine \DBAL \Driver \Connection ;
9
+ use Doctrine \DBAL \Driver \PgSQL \Driver ;
10
+ use Doctrine \DBAL \Tests \Driver \AbstractPostgreSQLDriverTestCase ;
11
+ use Doctrine \DBAL \Tests \TestUtil ;
12
+ use PHPUnit \Framework \Attributes \RequiresPhpExtension ;
13
+
14
+ class DriverTest extends AbstractPostgreSQLDriverTestCase
15
+ {
16
+ protected function setUp (): void
17
+ {
18
+ parent ::setUp ();
19
+
20
+ if (isset ($ GLOBALS ['db_driver ' ]) && $ GLOBALS ['db_driver ' ] === 'pgsql ' ) {
21
+ return ;
22
+ }
23
+
24
+ self ::markTestSkipped ('Test enabled only when using pgsql specific phpunit.xml ' );
25
+ }
26
+
27
+ /**
28
+ * Ensure we can handle URI notation for IPv6 addresses
29
+ */
30
+ #[RequiresPhpExtension('pgsql ' )]
31
+ public function testConnectionIPv6 (): void
32
+ {
33
+ $ params = TestUtil::getConnectionParams ();
34
+ $ params ['host ' ] = '[::1] ' ;
35
+
36
+ $ connection = $ this ->connect ((array )$ params );
37
+
38
+ self ::assertInstanceOf (Connection::class, $ connection );
39
+ }
40
+
41
+ protected function createDriver (): DriverInterface
42
+ {
43
+ return new Driver ();
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments