Skip to content

Commit c473688

Browse files
authored
Tests: Support ssl in ReflectorFactory (#626)
1 parent b413303 commit c473688

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ DBA_HOST=mysql80.ab
22
DBA_USER=testuser
33
DBA_PASSWORD=test
44
DBA_DATABASE=phpstan_dba
5+
DBA_SSL=0
56
DBA_MODE=recording
67
DBA_REFLECTOR=mysqli

tests/ReflectorFactory.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace staabm\PHPStanDba\Tests;
66

7-
use mysqli;
87
use PDO;
98
use staabm\PHPStanDba\DbSchema\SchemaHasherMysql;
109
use staabm\PHPStanDba\QueryReflection\MysqliQueryReflector;
@@ -32,13 +31,15 @@ public static function create(string $cacheDir): QueryReflector
3231
$user = getenv('DBA_USER') ?: 'root';
3332
$password = getenv('DBA_PASSWORD') ?: 'root';
3433
$dbname = getenv('DBA_DATABASE') ?: 'phpstan_dba';
34+
$ssl = false;
3535
$mode = getenv('DBA_MODE') ?: self::MODE_RECORDING;
3636
$reflector = getenv('DBA_REFLECTOR') ?: 'mysqli';
3737
} else {
3838
$host = getenv('DBA_HOST') ?: $_ENV['DBA_HOST'];
3939
$user = getenv('DBA_USER') ?: $_ENV['DBA_USER'];
4040
$password = getenv('DBA_PASSWORD') ?: $_ENV['DBA_PASSWORD'];
4141
$dbname = getenv('DBA_DATABASE') ?: $_ENV['DBA_DATABASE'];
42+
$ssl = (bool) (getenv('DBA_SSL') ?: $_ENV['DBA_SSL'] ?? false);
4243
$mode = getenv('DBA_MODE') ?: $_ENV['DBA_MODE'];
4344
$reflector = getenv('DBA_REFLECTOR') ?: $_ENV['DBA_REFLECTOR'];
4445
}
@@ -71,7 +72,11 @@ public static function create(string $cacheDir): QueryReflector
7172
$schemaHasher = null;
7273

7374
if ('mysqli' === $reflector) {
74-
$mysqli = new mysqli($host, $user, $password, $dbname);
75+
$mysqli = mysqli_init();
76+
if (! $mysqli) {
77+
throw new \RuntimeException('Unable to init mysqli');
78+
}
79+
$mysqli->real_connect($host, $user, $password, $dbname, null, null, $ssl ? MYSQLI_CLIENT_SSL : 0);
7580
$reflector = new MysqliQueryReflector($mysqli);
7681
$schemaHasher = new SchemaHasherMysql($mysqli);
7782
} elseif ('pdo-mysql' === $reflector) {

0 commit comments

Comments
 (0)