Skip to content

Commit 92a5085

Browse files
committed
Support localhost:port notation for tests
1 parent a2d990f commit 92a5085

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tests/ReflectorFactory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ public static function create(string $cacheDir): QueryReflector
7474
if (self::MODE_RECORDING === $mode || self::MODE_REPLAY_AND_RECORDING === $mode) {
7575
$schemaHasher = null;
7676

77+
$port = null;
78+
if (str_contains($host, ':')) {
79+
[$host, $port] = explode(':', $host, 2);
80+
}
81+
7782
if ('mysqli' === $reflector) {
7883
$mysqli = mysqli_init();
7984
if (! $mysqli) {
8085
throw new \RuntimeException('Unable to init mysqli');
8186
}
82-
$mysqli->real_connect($host, $user, $password, $dbname, null, null, $ssl ? MYSQLI_CLIENT_SSL : 0);
87+
$mysqli->real_connect($host, $user, $password, $dbname, $port, null, $ssl ? MYSQLI_CLIENT_SSL : 0);
8388
$reflector = new MysqliQueryReflector($mysqli);
8489
$schemaHasher = new SchemaHasherMysql($mysqli);
8590
} elseif ('pdo-mysql' === $reflector) {
@@ -88,11 +93,11 @@ public static function create(string $cacheDir): QueryReflector
8893
$options[PDO::MYSQL_ATTR_SSL_CA] = $ssl;
8994
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
9095
}
91-
$pdo = new PDO(sprintf('mysql:dbname=%s;host=%s', $dbname, $host), $user, $password, $options);
96+
$pdo = new PDO(sprintf('mysql:dbname=%s;host=%s;port=%s', $dbname, $host, $port), $user, $password, $options);
9297
$reflector = new PdoMysqlQueryReflector($pdo);
9398
$schemaHasher = new SchemaHasherMysql($pdo);
9499
} elseif ('pdo-pgsql' === $reflector) {
95-
$pdo = new PDO(sprintf('pgsql:dbname=%s;host=%s', $dbname, $host), $user, $password);
100+
$pdo = new PDO(sprintf('pgsql:dbname=%s;host=%s;port=%s', $dbname, $host, $port), $user, $password);
96101
$reflector = new PdoPgSqlQueryReflector($pdo);
97102
} else {
98103
throw new \RuntimeException('Unknown reflector: ' . $reflector);

0 commit comments

Comments
 (0)