Skip to content

Commit

Permalink
Support localhost:port notation for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Nov 27, 2024
1 parent a2d990f commit 92a5085
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/ReflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ 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);
}

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 +93,11 @@ 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);
$pdo = new PDO(sprintf('mysql:dbname=%s;host=%s;port=%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);
$pdo = new PDO(sprintf('pgsql:dbname=%s;host=%s;port=%s', $dbname, $host, $port), $user, $password);
$reflector = new PdoPgSqlQueryReflector($pdo);
} else {
throw new \RuntimeException('Unknown reflector: ' . $reflector);
Expand Down

0 comments on commit 92a5085

Please sign in to comment.