Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support localhost:port notation for tests #723

Merged
merged 7 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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