Add the possibility to specify driver options in test configuration

parent 76564ab8
...@@ -28,10 +28,11 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase ...@@ -28,10 +28,11 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
$params = $this->connection->getParams(); $params = $this->connection->getParams();
unset($params['dbname']); unset($params['dbname']);
$user = $params['user'] ?? null; $user = $params['user'] ?? null;
$password = $params['password'] ?? null; $password = $params['password'] ?? null;
$driverOptions = $params['driverOptions'] ?? [];
$connection = $this->driver->connect($params, $user, $password); $connection = $this->driver->connect($params, $user, $password, $driverOptions);
self::assertInstanceOf(DriverConnection::class, $connection); self::assertInstanceOf(DriverConnection::class, $connection);
} }
......
...@@ -8,6 +8,8 @@ use Doctrine\DBAL\Driver\Mysqli\MysqliException; ...@@ -8,6 +8,8 @@ use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\DbalFunctionalTestCase;
use Doctrine\Tests\TestUtil; use Doctrine\Tests\TestUtil;
use function array_merge;
use const MYSQLI_OPT_CONNECT_TIMEOUT; use const MYSQLI_OPT_CONNECT_TIMEOUT;
/** /**
...@@ -54,6 +56,10 @@ class ConnectionTest extends DbalFunctionalTestCase ...@@ -54,6 +56,10 @@ class ConnectionTest extends DbalFunctionalTestCase
{ {
$params = TestUtil::getConnectionParams(); $params = TestUtil::getConnectionParams();
if (isset($params['driverOptions'])) {
$driverOptions = array_merge($params['driverOptions'], $driverOptions);
}
return new MysqliConnection( return new MysqliConnection(
$params, $params,
$params['user'] ?? '', $params['user'] ?? '',
......
...@@ -9,6 +9,8 @@ use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; ...@@ -9,6 +9,8 @@ use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest;
use Doctrine\Tests\TestUtil; use Doctrine\Tests\TestUtil;
use PDO; use PDO;
use function array_merge;
/** /**
* @requires extension pdo_sqlsrv * @requires extension pdo_sqlsrv
*/ */
...@@ -42,6 +44,10 @@ class DriverTest extends AbstractDriverTest ...@@ -42,6 +44,10 @@ class DriverTest extends AbstractDriverTest
{ {
$params = TestUtil::getConnectionParams(); $params = TestUtil::getConnectionParams();
if (isset($params['driverOptions'])) {
$driverOptions = array_merge($params['driverOptions'], $driverOptions);
}
return $this->connection->getDriver()->connect( return $this->connection->getDriver()->connect(
$params, $params,
$params['user'] ?? '', $params['user'] ?? '',
......
...@@ -114,10 +114,11 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -114,10 +114,11 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$params['dbname'] = 'test_drop_database'; $params['dbname'] = 'test_drop_database';
} }
$user = $params['user'] ?? null; $user = $params['user'] ?? null;
$password = $params['password'] ?? null; $password = $params['password'] ?? null;
$driverOptions = $params['driverOptions'] ?? [];
$connection = $this->connection->getDriver()->connect($params, $user, $password); $connection = $this->connection->getDriver()->connect($params, $user, $password, $driverOptions);
self::assertInstanceOf(Connection::class, $connection); self::assertInstanceOf(Connection::class, $connection);
......
...@@ -43,10 +43,11 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -43,10 +43,11 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$params = $this->connection->getParams(); $params = $this->connection->getParams();
$params['dbname'] = 'test_drop_database'; $params['dbname'] = 'test_drop_database';
$user = $params['user'] ?? null; $user = $params['user'] ?? null;
$password = $params['password'] ?? null; $password = $params['password'] ?? null;
$driverOptions = $params['driverOptions'] ?? [];
$connection = $this->connection->getDriver()->connect($params, $user, $password); $connection = $this->connection->getDriver()->connect($params, $user, $password, $driverOptions);
self::assertInstanceOf(Connection::class, $connection); self::assertInstanceOf(Connection::class, $connection);
......
...@@ -8,6 +8,9 @@ use PHPUnit\Framework\Assert; ...@@ -8,6 +8,9 @@ use PHPUnit\Framework\Assert;
use function explode; use function explode;
use function extension_loaded; use function extension_loaded;
use function strlen;
use function strpos;
use function substr;
use function unlink; use function unlink;
/** /**
...@@ -190,6 +193,14 @@ class TestUtil ...@@ -190,6 +193,14 @@ class TestUtil
$parameters[$parameter] = $configuration[$prefix . $parameter]; $parameters[$parameter] = $configuration[$prefix . $parameter];
} }
foreach ($configuration as $param => $value) {
if (strpos($param, $prefix . 'driver_option_') !== 0) {
continue;
}
$parameters['driverOptions'][substr($param, strlen($prefix . 'driver_option_'))] = $value;
}
return $parameters; return $parameters;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment