Skip to content

Commit a128a1c

Browse files
authored
Support localhost:port notation for tests (#723)
1 parent a2d990f commit a128a1c

File tree

5 files changed

+68
-60
lines changed

5 files changed

+68
-60
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpstan-dba-pdo-mysql.cache

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/ReflectorFactory.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function create(string $cacheDir): QueryReflector
4343
$ssl = (string) (getenv('DBA_SSL') ?: $_ENV['DBA_SSL'] ?? '');
4444
$mode = getenv('DBA_MODE') ?: $_ENV['DBA_MODE'];
4545
$reflector = getenv('DBA_REFLECTOR') ?: $_ENV['DBA_REFLECTOR'];
46-
$platform = getenv('DBA_PLATFORM') ?: $_ENV['DBA_PLATFORM'];
46+
$platform = getenv('DBA_PLATFORM') ?: $_ENV['DBA_PLATFORM'] ?? '';
4747
}
4848

4949
// make env vars available to tests, in case non are defined yet
@@ -74,12 +74,18 @@ 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+
$port = (int) $port;
81+
}
82+
7783
if ('mysqli' === $reflector) {
7884
$mysqli = mysqli_init();
7985
if (! $mysqli) {
8086
throw new \RuntimeException('Unable to init mysqli');
8187
}
82-
$mysqli->real_connect($host, $user, $password, $dbname, null, null, $ssl ? MYSQLI_CLIENT_SSL : 0);
88+
$mysqli->real_connect($host, $user, $password, $dbname, $port, null, $ssl ? MYSQLI_CLIENT_SSL : 0);
8389
$reflector = new MysqliQueryReflector($mysqli);
8490
$schemaHasher = new SchemaHasherMysql($mysqli);
8591
} elseif ('pdo-mysql' === $reflector) {
@@ -88,11 +94,13 @@ public static function create(string $cacheDir): QueryReflector
8894
$options[PDO::MYSQL_ATTR_SSL_CA] = $ssl;
8995
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
9096
}
91-
$pdo = new PDO(sprintf('mysql:dbname=%s;host=%s', $dbname, $host), $user, $password, $options);
97+
$port = $port !== null ? ';port=' . $port : '';
98+
$pdo = new PDO(sprintf('mysql:dbname=%s;host=%s', $dbname, $host) . $port, $user, $password, $options);
9299
$reflector = new PdoMysqlQueryReflector($pdo);
93100
$schemaHasher = new SchemaHasherMysql($pdo);
94101
} elseif ('pdo-pgsql' === $reflector) {
95-
$pdo = new PDO(sprintf('pgsql:dbname=%s;host=%s', $dbname, $host), $user, $password);
102+
$port = $port !== null ? ';port=' . $port : '';
103+
$pdo = new PDO(sprintf('pgsql:dbname=%s;host=%s', $dbname, $host) . $port, $user, $password);
96104
$reflector = new PdoPgSqlQueryReflector($pdo);
97105
} else {
98106
throw new \RuntimeException('Unknown reflector: ' . $reflector);

tests/sqlAst/config/.phpunit-phpstan-dba-mysqli.cache

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)