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

Tests: Support ssl in ReflectorFactory #626

Merged
merged 9 commits into from
Sep 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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