From c6e9d755a6e62a7958ed51d5e303472449e54fa6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 12 Jun 2020 15:17:01 -0700 Subject: [PATCH] Simplify Driver::connect() signature --- phpcs.xml.dist | 5 +- src/Connection.php | 6 +- .../PrimaryReadReplicaConnection.php | 7 +- src/Driver.php | 12 +- src/Driver/IBMDB2/DB2Connection.php | 22 ++-- src/Driver/IBMDB2/DB2Driver.php | 15 +-- src/Driver/Mysqli/Driver.php | 104 ++++++++++++++- src/Driver/Mysqli/MysqliConnection.php | 120 ++++-------------- src/Driver/OCI8/Driver.php | 6 +- src/Driver/PDOMySql/Driver.php | 8 +- src/Driver/PDOOracle/Driver.php | 8 +- src/Driver/PDOPgSql/Driver.php | 10 +- src/Driver/PDOSqlite/Driver.php | 8 +- src/Driver/PDOSqlsrv/Driver.php | 18 +-- src/Driver/SQLSrv/Driver.php | 12 +- tests/Driver/Mysqli/MysqliConnectionTest.php | 3 +- tests/Driver/PDOPgSql/DriverTest.php | 16 +-- .../Functional/Driver/AbstractDriverTest.php | 5 +- .../Driver/Mysqli/ConnectionTest.php | 11 +- .../Functional/Driver/PDOPgSql/DriverTest.php | 5 +- .../Driver/PDOSqlsrv/DriverTest.php | 12 +- .../SchemaManagerFunctionalTestCase.php | 5 +- .../Schema/SqliteSchemaManagerTest.php | 5 +- 23 files changed, 216 insertions(+), 207 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index a9607273e9d..c7917559c5f 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -83,11 +83,12 @@ src/Driver/IBMDB2/DB2Connection.php + src/Driver/Mysqli/MysqliConnection.php src/SQLParserUtils.php src/Tools/Dumper.php diff --git a/src/Connection.php b/src/Connection.php index 4f741bb3c3d..f07d9f49151 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -352,12 +352,8 @@ public function connect() return false; } - $driverOptions = $this->params['driverOptions'] ?? []; - $user = $this->params['user'] ?? null; - $password = $this->params['password'] ?? null; - try { - $this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions); + $this->_conn = $this->_driver->connect($this->params); } catch (DriverException $e) { throw DBALException::driverException($this->_driver, $e); } diff --git a/src/Connections/PrimaryReadReplicaConnection.php b/src/Connections/PrimaryReadReplicaConnection.php index 8e3c6ee136b..d1d9810d965 100644 --- a/src/Connections/PrimaryReadReplicaConnection.php +++ b/src/Connections/PrimaryReadReplicaConnection.php @@ -225,15 +225,10 @@ protected function connectTo($connectionName) { $params = $this->getParams(); - $driverOptions = $params['driverOptions'] ?? []; - $connectionParams = $this->chooseConnectionConfiguration($connectionName, $params); - $user = $connectionParams['user'] ?? null; - $password = $connectionParams['password'] ?? null; - try { - return $this->_driver->connect($connectionParams, $user, $password, $driverOptions); + return $this->_driver->connect($connectionParams); } catch (DriverException $e) { throw DBALException::driverException($this->_driver, $e); } diff --git a/src/Driver.php b/src/Driver.php index f0b300aee98..ec8fbfb7022 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; @@ -15,18 +16,13 @@ interface Driver /** * Attempts to create a connection with the database. * - * The usage of NULL to indicate empty username or password is deprecated. Use an empty string instead. + * @param mixed[] $params All connection parameters. * - * @param mixed[] $params All connection parameters passed by the user. - * @param string|null $username The username to use when connecting. - * @param string|null $password The password to use when connecting. - * @param mixed[] $driverOptions The driver options to use when connecting. - * - * @return \Doctrine\DBAL\Driver\Connection The database connection. + * @return DriverConnection The database connection. * * @throws DriverException */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []); + public function connect(array $params); /** * Gets the DatabasePlatform instance that provides all the metadata about diff --git a/src/Driver/IBMDB2/DB2Connection.php b/src/Driver/IBMDB2/DB2Connection.php index c6a120cc916..1e8bdf51a05 100644 --- a/src/Driver/IBMDB2/DB2Connection.php +++ b/src/Driver/IBMDB2/DB2Connection.php @@ -33,21 +33,21 @@ class DB2Connection implements ServerInfoAwareConnection private $conn = null; /** - * @param mixed[] $params - * @param string $username - * @param string $password - * @param mixed[] $driverOptions + * @param array $driverOptions * * @throws DB2Exception */ - public function __construct(array $params, $username, $password, $driverOptions = []) - { - $isPersistent = (isset($params['persistent']) && $params['persistent'] === true); - - if ($isPersistent) { - $conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions); + public function __construct( + string $database, + bool $persistent, + string $username, + string $password, + array $driverOptions = [] + ) { + if ($persistent) { + $conn = db2_pconnect($database, $username, $password, $driverOptions); } else { - $conn = db2_connect($params['dbname'], $username, $password, $driverOptions); + $conn = db2_connect($database, $username, $password, $driverOptions); } if ($conn === false) { diff --git a/src/Driver/IBMDB2/DB2Driver.php b/src/Driver/IBMDB2/DB2Driver.php index 650d75ceac7..4712e144aef 100644 --- a/src/Driver/IBMDB2/DB2Driver.php +++ b/src/Driver/IBMDB2/DB2Driver.php @@ -12,17 +12,14 @@ class DB2Driver extends AbstractDB2Driver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) { - $params['user'] = $username; - $params['password'] = $password; - $params['dbname'] = DataSourceName::fromConnectionParameters($params)->toString(); - return new DB2Connection( - $params, - (string) $username, - (string) $password, - $driverOptions + DataSourceName::fromConnectionParameters($params)->toString(), + isset($params['persistent']) && $params['persistent'] === true, + $params['user'] ?? '', + $params['password'] ?? '', + $params['driver_options'] ?? [] ); } diff --git a/src/Driver/Mysqli/Driver.php b/src/Driver/Mysqli/Driver.php index 4430482dfc9..c13a3f81709 100644 --- a/src/Driver/Mysqli/Driver.php +++ b/src/Driver/Mysqli/Driver.php @@ -3,15 +3,115 @@ namespace Doctrine\DBAL\Driver\Mysqli; use Doctrine\DBAL\Driver\AbstractMySQLDriver; +use Doctrine\DBAL\Driver\Mysqli\Initializer\Charset; +use Doctrine\DBAL\Driver\Mysqli\Initializer\Options; +use Doctrine\DBAL\Driver\Mysqli\Initializer\Secure; + +use function count; class Driver extends AbstractMySQLDriver { /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) + { + if (! empty($params['persistent'])) { + if (! isset($params['host'])) { + throw HostRequired::forPersistentConnection(); + } + + $host = 'p:' . $params['host']; + } else { + $host = $params['host'] ?? null; + } + + $flags = null; + + $preInitializers = $postInitializers = []; + + if (isset($params['driver_options'])) { + $driverOptions = $params['driver_options']; + + if (isset($driverOptions[MysqliConnection::OPTION_FLAGS])) { + $flags = $driverOptions[MysqliConnection::OPTION_FLAGS]; + unset($driverOptions[MysqliConnection::OPTION_FLAGS]); + } + + $preInitializers = $this->withOptions($preInitializers, $driverOptions); + } + + $preInitializers = $this->withSecure($preInitializers, $params); + $postInitializers = $this->withCharset($postInitializers, $params); + + return new MysqliConnection( + $host, + $params['user'] ?? null, + $params['password'] ?? null, + $params['dbname'] ?? null, + $params['port'] ?? null, + $params['unix_socket'] ?? null, + $flags, + $preInitializers, + $postInitializers + ); + } + + /** + * @param list $initializers + * @param array $options + * + * @return list + */ + private function withOptions(array $initializers, array $options): array { - return new MysqliConnection($params, (string) $username, (string) $password, $driverOptions); + if (count($options) !== 0) { + $initializers[] = new Options($options); + } + + return $initializers; + } + + /** + * @param list $initializers + * @param array $params + * + * @return list + */ + private function withSecure(array $initializers, array $params): array + { + if ( + isset($params['ssl_key']) || + isset($params['ssl_cert']) || + isset($params['ssl_ca']) || + isset($params['ssl_capath']) || + isset($params['ssl_cipher']) + ) { + $initializers[] = new Secure( + $params['ssl_key'] ?? null, + $params['ssl_cert'] ?? null, + $params['ssl_ca'] ?? null, + $params['ssl_capath'] ?? null, + $params['ssl_cipher'] ?? null + ); + } + + return $initializers; + } + + /** + * @param list $initializers + * @param array $params + * + * @return list + */ + private function withCharset(array $initializers, array $params): array + { + if (isset($params['charset'])) { + $initializers[] = new Charset($params['charset']); + } + + return $initializers; } /** diff --git a/src/Driver/Mysqli/MysqliConnection.php b/src/Driver/Mysqli/MysqliConnection.php index 39d7f49fedf..de3e3c71c4c 100644 --- a/src/Driver/Mysqli/MysqliConnection.php +++ b/src/Driver/Mysqli/MysqliConnection.php @@ -2,9 +2,6 @@ namespace Doctrine\DBAL\Driver\Mysqli; -use Doctrine\DBAL\Driver\Mysqli\Initializer\Charset; -use Doctrine\DBAL\Driver\Mysqli\Initializer\Options; -use Doctrine\DBAL\Driver\Mysqli\Initializer\Secure; use Doctrine\DBAL\Driver\PingableConnection; use Doctrine\DBAL\Driver\Result as ResultInterface; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; @@ -12,9 +9,7 @@ use Doctrine\DBAL\ParameterType; use mysqli; -use function count; use function floor; -use function ini_get; use function mysqli_init; use function stripos; @@ -29,55 +24,41 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection private $conn; /** - * @param mixed[] $params - * @param string $username - * @param string $password - * @param mixed[] $driverOptions + * @param iterable $preInitializers + * @param iterable $postInitializers * * @throws MysqliException */ - public function __construct(array $params, $username, $password, array $driverOptions = []) - { - $socket = $params['unix_socket'] ?? ini_get('mysqli.default_socket'); - $dbname = $params['dbname'] ?? null; - $port = $params['port'] ?? null; - - if (! empty($params['persistent'])) { - if (! isset($params['host'])) { - throw HostRequired::forPersistentConnection(); - } - - $host = 'p:' . $params['host']; - } else { - $host = $params['host'] ?? null; - } - - $flags = $driverOptions[static::OPTION_FLAGS] ?? null; - unset($driverOptions[static::OPTION_FLAGS]); - - $this->conn = mysqli_init(); - - $preInitializers = $postInitializers = []; - - $preInitializers = $this->withOptions($preInitializers, $driverOptions); - $preInitializers = $this->withSecure($preInitializers, $params); - $postInitializers = $this->withCharset($postInitializers, $params); + public function __construct( + ?string $host = null, + ?string $username = null, + ?string $password = null, + ?string $database = null, + ?int $port = null, + ?string $socket = null, + ?int $flags = null, + iterable $preInitializers = [], + iterable $postInitializers = [] + ) { + $connection = mysqli_init(); foreach ($preInitializers as $initializer) { - $initializer->initialize($this->conn); + $initializer->initialize($connection); } - if (! @$this->conn->real_connect($host, $username, $password, $dbname, $port, $socket, $flags)) { + if (! @$connection->real_connect($host, $username, $password, $database, $port, $socket, $flags)) { throw new MysqliException( - $this->conn->connect_error, - $this->conn->sqlstate ?? 'HY000', - $this->conn->connect_errno + $connection->connect_error, + 'HY000', + $connection->connect_errno ); } foreach ($postInitializers as $initializer) { - $initializer->initialize($this->conn); + $initializer->initialize($connection); } + + $this->conn = $connection; } /** @@ -192,61 +173,4 @@ public function ping() { return $this->conn->ping(); } - - /** - * @param list $initializers - * @param array $options - * - * @return list - */ - private function withOptions(array $initializers, array $options): array - { - if (count($options) !== 0) { - $initializers[] = new Options($options); - } - - return $initializers; - } - - /** - * @param list $initializers - * @param array $params - * - * @return list - */ - private function withSecure(array $initializers, array $params): array - { - if ( - isset($params['ssl_key']) || - isset($params['ssl_cert']) || - isset($params['ssl_ca']) || - isset($params['ssl_capath']) || - isset($params['ssl_cipher']) - ) { - $initializers[] = new Secure( - $params['ssl_key'] ?? null, - $params['ssl_cert'] ?? null, - $params['ssl_ca'] ?? null, - $params['ssl_capath'] ?? null, - $params['ssl_cipher'] ?? null - ); - } - - return $initializers; - } - - /** - * @param list $initializers - * @param array $params - * - * @return list - */ - private function withCharset(array $initializers, array $params): array - { - if (isset($params['charset'])) { - $initializers[] = new Charset($params['charset']); - } - - return $initializers; - } } diff --git a/src/Driver/OCI8/Driver.php b/src/Driver/OCI8/Driver.php index e2df60e2d52..88436af21ff 100644 --- a/src/Driver/OCI8/Driver.php +++ b/src/Driver/OCI8/Driver.php @@ -14,11 +14,11 @@ class Driver extends AbstractOracleDriver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) { return new OCI8Connection( - (string) $username, - (string) $password, + $params['user'] ?? '', + $params['password'] ?? '', $this->_constructDsn($params), $params['charset'] ?? '', $params['sessionMode'] ?? OCI_NO_AUTO_COMMIT, diff --git a/src/Driver/PDOMySql/Driver.php b/src/Driver/PDOMySql/Driver.php index 3beb43bc7a1..6d65a2b6686 100644 --- a/src/Driver/PDOMySql/Driver.php +++ b/src/Driver/PDOMySql/Driver.php @@ -14,16 +14,18 @@ class Driver extends AbstractMySQLDriver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) { + $driverOptions = $params['driver_options'] ?? []; + if (! empty($params['persistent'])) { $driverOptions[PDO::ATTR_PERSISTENT] = true; } return new PDOConnection( $this->constructPdoDsn($params), - $username, - $password, + $params['user'] ?? '', + $params['password'] ?? '', $driverOptions ); } diff --git a/src/Driver/PDOOracle/Driver.php b/src/Driver/PDOOracle/Driver.php index 3267b6bf823..c3bba5501f2 100644 --- a/src/Driver/PDOOracle/Driver.php +++ b/src/Driver/PDOOracle/Driver.php @@ -19,16 +19,18 @@ class Driver extends AbstractOracleDriver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) { + $driverOptions = $params['driver_options'] ?? []; + if (! empty($params['persistent'])) { $driverOptions[PDO::ATTR_PERSISTENT] = true; } return new PDOConnection( $this->constructPdoDsn($params), - $username, - $password, + $params['user'] ?? '', + $params['password'] ?? '', $driverOptions ); } diff --git a/src/Driver/PDOPgSql/Driver.php b/src/Driver/PDOPgSql/Driver.php index cd352fc636f..fbeb0b5ee11 100644 --- a/src/Driver/PDOPgSql/Driver.php +++ b/src/Driver/PDOPgSql/Driver.php @@ -16,17 +16,19 @@ class Driver extends AbstractPostgreSQLDriver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) { + $driverOptions = $params['driver_options'] ?? []; + if (! empty($params['persistent'])) { $driverOptions[PDO::ATTR_PERSISTENT] = true; } $connection = new PDOConnection( $this->_constructPdoDsn($params), - $username, - $password, - $driverOptions + $params['user'] ?? '', + $params['password'] ?? '', + $driverOptions, ); if ( diff --git a/src/Driver/PDOSqlite/Driver.php b/src/Driver/PDOSqlite/Driver.php index 779c2576cb8..75bad95a9d6 100644 --- a/src/Driver/PDOSqlite/Driver.php +++ b/src/Driver/PDOSqlite/Driver.php @@ -23,8 +23,10 @@ class Driver extends AbstractSQLiteDriver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) { + $driverOptions = $params['driver_options'] ?? []; + if (isset($driverOptions['userDefinedFunctions'])) { $this->_userDefinedFunctions = array_merge( $this->_userDefinedFunctions, @@ -35,8 +37,8 @@ public function connect(array $params, $username = null, $password = null, array $connection = new PDOConnection( $this->_constructPdoDsn($params), - $username, - $password, + $params['user'] ?? '', + $params['password'] ?? '', $driverOptions ); diff --git a/src/Driver/PDOSqlsrv/Driver.php b/src/Driver/PDOSqlsrv/Driver.php index e3aa4e1066b..aa94dcf4491 100644 --- a/src/Driver/PDOSqlsrv/Driver.php +++ b/src/Driver/PDOSqlsrv/Driver.php @@ -16,15 +16,17 @@ class Driver extends AbstractSQLServerDriver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) { $pdoOptions = $dsnOptions = []; - foreach ($driverOptions as $option => $value) { - if (is_int($option)) { - $pdoOptions[$option] = $value; - } else { - $dsnOptions[$option] = $value; + if (isset($params['driver_options'])) { + foreach ($params['driver_options'] as $option => $value) { + if (is_int($option)) { + $pdoOptions[$option] = $value; + } else { + $dsnOptions[$option] = $value; + } } } @@ -34,8 +36,8 @@ public function connect(array $params, $username = null, $password = null, array return new Connection( $this->_constructPdoDsn($params, $dsnOptions), - $username, - $password, + $params['user'] ?? '', + $params['password'] ?? '', $pdoOptions ); } diff --git a/src/Driver/SQLSrv/Driver.php b/src/Driver/SQLSrv/Driver.php index 848ab5eef91..91a98cd902a 100644 --- a/src/Driver/SQLSrv/Driver.php +++ b/src/Driver/SQLSrv/Driver.php @@ -12,7 +12,7 @@ class Driver extends AbstractSQLServerDriver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + public function connect(array $params) { if (! isset($params['host'])) { throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver."); @@ -23,6 +23,8 @@ public function connect(array $params, $username = null, $password = null, array $serverName .= ', ' . $params['port']; } + $driverOptions = $params['driver_options'] ?? []; + if (isset($params['dbname'])) { $driverOptions['Database'] = $params['dbname']; } @@ -31,12 +33,12 @@ public function connect(array $params, $username = null, $password = null, array $driverOptions['CharacterSet'] = $params['charset']; } - if ($username !== null) { - $driverOptions['UID'] = $username; + if (isset($params['user'])) { + $driverOptions['UID'] = $params['user']; } - if ($password !== null) { - $driverOptions['PWD'] = $password; + if (isset($params['password'])) { + $driverOptions['PWD'] = $params['password']; } if (! isset($driverOptions['ReturnDatesAsStrings'])) { diff --git a/tests/Driver/Mysqli/MysqliConnectionTest.php b/tests/Driver/Mysqli/MysqliConnectionTest.php index afbfc2d5d47..5791fd5d859 100644 --- a/tests/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Driver/Mysqli/MysqliConnectionTest.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Tests\Driver\Mysqli; +use Doctrine\DBAL\Driver\Mysqli\Driver; use Doctrine\DBAL\Driver\Mysqli\HostRequired; use Doctrine\DBAL\Driver\Mysqli\MysqliConnection; use Doctrine\DBAL\Platforms\MySqlPlatform; @@ -44,6 +45,6 @@ public function testDoesNotRequireQueryForServerVersion(): void public function testHostnameIsRequiredForPersistentConnection(): void { $this->expectException(HostRequired::class); - new MysqliConnection(['persistent' => 'true'], '', ''); + (new Driver())->connect(['persistent' => 'true']); } } diff --git a/tests/Driver/PDOPgSql/DriverTest.php b/tests/Driver/PDOPgSql/DriverTest.php index dda472dd950..1cd737e804c 100644 --- a/tests/Driver/PDOPgSql/DriverTest.php +++ b/tests/Driver/PDOPgSql/DriverTest.php @@ -3,13 +3,15 @@ namespace Doctrine\DBAL\Tests\Driver\PDOPgSql; use Doctrine\DBAL\Driver as DriverInterface; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\DBAL\Tests\Driver\AbstractPostgreSQLDriverTest; use Doctrine\DBAL\Tests\TestUtil; use PDO; use PDOException; +use function array_merge; + class DriverTest extends AbstractPostgreSQLDriverTest { public function testReturnsName(): void @@ -92,15 +94,13 @@ private function skipWhenNotUsingPdoPgsql(): void /** * @param array $driverOptions */ - private function connect(array $driverOptions): PDOConnection + private function connect(array $driverOptions): Connection { - $params = TestUtil::getConnectionParams(); - return $this->createDriver()->connect( - $params, - $params['user'] ?? '', - $params['password'] ?? '', - $driverOptions + array_merge( + TestUtil::getConnectionParams(), + ['driver_options' => $driverOptions] + ) ); } } diff --git a/tests/Functional/Driver/AbstractDriverTest.php b/tests/Functional/Driver/AbstractDriverTest.php index 7ac7709fdea..86e2a73b755 100644 --- a/tests/Functional/Driver/AbstractDriverTest.php +++ b/tests/Functional/Driver/AbstractDriverTest.php @@ -31,10 +31,7 @@ public function testConnectsWithoutDatabaseNameParameter(): void $params = $this->connection->getParams(); unset($params['dbname']); - $user = $params['user'] ?? null; - $password = $params['password'] ?? null; - - $connection = $this->driver->connect($params, $user, $password); + $connection = $this->driver->connect($params); self::assertInstanceOf(DriverConnection::class, $connection); } diff --git a/tests/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Functional/Driver/Mysqli/ConnectionTest.php index bd16948c794..435a612b69c 100644 --- a/tests/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Functional/Driver/Mysqli/ConnectionTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Tests\TestUtil; +use function array_merge; use function extension_loaded; use const MYSQLI_OPT_CONNECT_TIMEOUT; @@ -73,11 +74,11 @@ private function getConnection(array $driverOptions): MysqliConnection { $params = TestUtil::getConnectionParams(); - return new MysqliConnection( - $params, - $params['user'] ?? '', - $params['password'] ?? '', - $driverOptions + return (new Driver())->connect( + array_merge( + $params, + ['driver_options' => $driverOptions] + ) ); } } diff --git a/tests/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Functional/Driver/PDOPgSql/DriverTest.php index e5db1a085c2..02901d16301 100644 --- a/tests/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Functional/Driver/PDOPgSql/DriverTest.php @@ -78,10 +78,7 @@ public function testConnectsWithApplicationNameParameter(): void $parameters = $this->connection->getParams(); $parameters['application_name'] = 'doctrine'; - $user = $parameters['user'] ?? null; - $password = $parameters['password'] ?? null; - - $connection = $this->driver->connect($parameters, $user, $password); + $connection = $this->driver->connect($parameters); $hash = microtime(true); // required to identify the record in the results uniquely $sql = sprintf('SELECT * FROM pg_stat_activity WHERE %d = %d', $hash, $hash); diff --git a/tests/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Functional/Driver/PDOSqlsrv/DriverTest.php index f568ff35c8f..65006c69c44 100644 --- a/tests/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -10,8 +10,8 @@ use Doctrine\DBAL\Tests\TestUtil; use PDO; +use function array_merge; use function assert; - use function extension_loaded; class DriverTest extends AbstractDriverTest @@ -46,13 +46,11 @@ protected static function getDatabaseNameForConnectionWithoutDatabaseNameParamet */ protected function getConnection(array $driverOptions): Connection { - $params = TestUtil::getConnectionParams(); - return $this->connection->getDriver()->connect( - $params, - $params['user'] ?? '', - $params['password'] ?? '', - $driverOptions + array_merge( + TestUtil::getConnectionParams(), + ['driver_options' => $driverOptions] + ) ); } diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index aa92bf9ab0d..f0ed94d17a5 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -117,10 +117,7 @@ public function testDropsDatabaseWithActiveConnections(): void $params['dbname'] = 'test_drop_database'; } - $user = $params['user'] ?? null; - $password = $params['password'] ?? null; - - $connection = $this->connection->getDriver()->connect($params, $user, $password); + $connection = $this->connection->getDriver()->connect($params); self::assertInstanceOf(Connection::class, $connection); diff --git a/tests/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Functional/Schema/SqliteSchemaManagerTest.php index 0ea1a4e4433..5cb5c8522c3 100644 --- a/tests/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Functional/Schema/SqliteSchemaManagerTest.php @@ -50,10 +50,7 @@ public function testDropsDatabaseWithActiveConnections(): void $params = $this->connection->getParams(); $params['dbname'] = 'test_drop_database'; - $user = $params['user'] ?? null; - $password = $params['password'] ?? null; - - $connection = $this->connection->getDriver()->connect($params, $user, $password); + $connection = $this->connection->getDriver()->connect($params); self::assertInstanceOf(Connection::class, $connection);