Skip to content

Commit

Permalink
Support localhost:port notation for tests (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Nov 27, 2024
1 parent a2d990f commit a128a1c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 60 deletions.
6 changes: 3 additions & 3 deletions .phpstan-dba-mysqli.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .phpstan-dba-pdo-mysql.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions tests/ReflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function create(string $cacheDir): QueryReflector
$ssl = (string) (getenv('DBA_SSL') ?: $_ENV['DBA_SSL'] ?? '');
$mode = getenv('DBA_MODE') ?: $_ENV['DBA_MODE'];
$reflector = getenv('DBA_REFLECTOR') ?: $_ENV['DBA_REFLECTOR'];
$platform = getenv('DBA_PLATFORM') ?: $_ENV['DBA_PLATFORM'];
$platform = getenv('DBA_PLATFORM') ?: $_ENV['DBA_PLATFORM'] ?? '';
}

// make env vars available to tests, in case non are defined yet
Expand Down Expand Up @@ -74,12 +74,18 @@ public static function create(string $cacheDir): QueryReflector
if (self::MODE_RECORDING === $mode || self::MODE_REPLAY_AND_RECORDING === $mode) {
$schemaHasher = null;

$port = null;
if (str_contains($host, ':')) {
[$host, $port] = explode(':', $host, 2);
$port = (int) $port;
}

if ('mysqli' === $reflector) {
$mysqli = mysqli_init();
if (! $mysqli) {
throw new \RuntimeException('Unable to init mysqli');
}
$mysqli->real_connect($host, $user, $password, $dbname, null, null, $ssl ? MYSQLI_CLIENT_SSL : 0);
$mysqli->real_connect($host, $user, $password, $dbname, $port, null, $ssl ? MYSQLI_CLIENT_SSL : 0);
$reflector = new MysqliQueryReflector($mysqli);
$schemaHasher = new SchemaHasherMysql($mysqli);
} elseif ('pdo-mysql' === $reflector) {
Expand All @@ -88,11 +94,13 @@ public static function create(string $cacheDir): QueryReflector
$options[PDO::MYSQL_ATTR_SSL_CA] = $ssl;
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
}
$pdo = new PDO(sprintf('mysql:dbname=%s;host=%s', $dbname, $host), $user, $password, $options);
$port = $port !== null ? ';port=' . $port : '';
$pdo = new PDO(sprintf('mysql:dbname=%s;host=%s', $dbname, $host) . $port, $user, $password, $options);
$reflector = new PdoMysqlQueryReflector($pdo);
$schemaHasher = new SchemaHasherMysql($pdo);
} elseif ('pdo-pgsql' === $reflector) {
$pdo = new PDO(sprintf('pgsql:dbname=%s;host=%s', $dbname, $host), $user, $password);
$port = $port !== null ? ';port=' . $port : '';
$pdo = new PDO(sprintf('pgsql:dbname=%s;host=%s', $dbname, $host) . $port, $user, $password);
$reflector = new PdoPgSqlQueryReflector($pdo);
} else {
throw new \RuntimeException('Unknown reflector: ' . $reflector);
Expand Down
50 changes: 25 additions & 25 deletions tests/sqlAst/config/.phpunit-phpstan-dba-mysqli.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a128a1c

Please sign in to comment.