Skip to content

Commit

Permalink
Tests: Support ssl in ReflectorFactory (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 28, 2023
1 parent b413303 commit c473688
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.dist
Expand Up @@ -2,5 +2,6 @@ DBA_HOST=mysql80.ab
DBA_USER=testuser
DBA_PASSWORD=test
DBA_DATABASE=phpstan_dba
DBA_SSL=0
DBA_MODE=recording
DBA_REFLECTOR=mysqli
9 changes: 7 additions & 2 deletions tests/ReflectorFactory.php
Expand Up @@ -4,7 +4,6 @@

namespace staabm\PHPStanDba\Tests;

use mysqli;
use PDO;
use staabm\PHPStanDba\DbSchema\SchemaHasherMysql;
use staabm\PHPStanDba\QueryReflection\MysqliQueryReflector;
Expand Down Expand Up @@ -32,13 +31,15 @@ public static function create(string $cacheDir): QueryReflector
$user = getenv('DBA_USER') ?: 'root';
$password = getenv('DBA_PASSWORD') ?: 'root';
$dbname = getenv('DBA_DATABASE') ?: 'phpstan_dba';
$ssl = false;
$mode = getenv('DBA_MODE') ?: self::MODE_RECORDING;
$reflector = getenv('DBA_REFLECTOR') ?: 'mysqli';
} else {
$host = getenv('DBA_HOST') ?: $_ENV['DBA_HOST'];
$user = getenv('DBA_USER') ?: $_ENV['DBA_USER'];
$password = getenv('DBA_PASSWORD') ?: $_ENV['DBA_PASSWORD'];
$dbname = getenv('DBA_DATABASE') ?: $_ENV['DBA_DATABASE'];
$ssl = (bool) (getenv('DBA_SSL') ?: $_ENV['DBA_SSL'] ?? false);
$mode = getenv('DBA_MODE') ?: $_ENV['DBA_MODE'];
$reflector = getenv('DBA_REFLECTOR') ?: $_ENV['DBA_REFLECTOR'];
}
Expand Down Expand Up @@ -71,7 +72,11 @@ public static function create(string $cacheDir): QueryReflector
$schemaHasher = null;

if ('mysqli' === $reflector) {
$mysqli = new mysqli($host, $user, $password, $dbname);
$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);
$reflector = new MysqliQueryReflector($mysqli);
$schemaHasher = new SchemaHasherMysql($mysqli);
} elseif ('pdo-mysql' === $reflector) {
Expand Down

0 comments on commit c473688

Please sign in to comment.