Unverified Commit b134e4af authored by Sergei Morozov's avatar Sergei Morozov

Merge branch '2.11.x' into 3.0.x

parents 4b2fed55 d2005239
...@@ -179,6 +179,11 @@ Please use other database client applications for import, e.g.: ...@@ -179,6 +179,11 @@ Please use other database client applications for import, e.g.:
# Upgrade to 2.11 # Upgrade to 2.11
## Deprecated `Doctrine\DBAL\Driver::getDatabase()`
- The usage of `Doctrine\DBAL\Driver::getDatabase()` is deprecated. Please use `Doctrine\DBAL\Connection::getDatabase()` instead.
- The behavior of the SQLite connection returning the database file path as the database is deprecated and shouldn't be relied upon.
## Deprecated `Portability\Connection::PORTABILITY_{PLATFORM}` constants` ## Deprecated `Portability\Connection::PORTABILITY_{PLATFORM}` constants`
The platform-specific portability mode flags are meant to be used only by the portability layer internally to optimize The platform-specific portability mode flags are meant to be used only by the portability layer internally to optimize
......
...@@ -11,18 +11,11 @@ ...@@ -11,18 +11,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="sqlsrv"/> <var name="db_driver" value="sqlsrv"/>
<var name="db_host" value="(local)\SQL2008R2SP2" /> <var name="db_host" value="(local)\SQL2008R2SP2" />
<var name="db_username" value="sa" /> <var name="db_user" value="sa" />
<var name="db_password" value="Password12!" /> <var name="db_password" value="Password12!" />
<var name="db_name" value="doctrine_tests" /> <var name="db_dbname" value="doctrine_tests" />
<var name="db_port" value="1433" />
<var name="tmpdb_type" value="sqlsrv"/>
<var name="tmpdb_host" value="(local)\SQL2008R2SP2" />
<var name="tmpdb_username" value="sa" />
<var name="tmpdb_password" value="Password12!" />
<var name="tmpdb_port" value="1433" />
</php> </php>
<testsuites> <testsuites>
......
...@@ -11,18 +11,11 @@ ...@@ -11,18 +11,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="sqlsrv"/> <var name="db_driver" value="sqlsrv"/>
<var name="db_host" value="(local)\SQL2012SP1" /> <var name="db_host" value="(local)\SQL2012SP1" />
<var name="db_username" value="sa" /> <var name="db_user" value="sa" />
<var name="db_password" value="Password12!" /> <var name="db_password" value="Password12!" />
<var name="db_name" value="doctrine_tests" /> <var name="db_dbname" value="doctrine_tests" />
<var name="db_port" value="1433" />
<var name="tmpdb_type" value="sqlsrv"/>
<var name="tmpdb_host" value="(local)\SQL2012SP1" />
<var name="tmpdb_username" value="sa" />
<var name="tmpdb_password" value="Password12!" />
<var name="tmpdb_port" value="1433" />
</php> </php>
<testsuites> <testsuites>
......
...@@ -11,18 +11,11 @@ ...@@ -11,18 +11,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="pdo_sqlsrv"/> <var name="db_driver" value="pdo_sqlsrv"/>
<var name="db_host" value="(local)\SQL2017" /> <var name="db_host" value="(local)\SQL2017" />
<var name="db_username" value="sa" /> <var name="db_user" value="sa" />
<var name="db_password" value="Password12!" /> <var name="db_password" value="Password12!" />
<var name="db_name" value="doctrine_tests" /> <var name="db_dbname" value="doctrine_tests" />
<var name="db_port" value="1433"/>
<var name="tmpdb_type" value="pdo_sqlsrv"/>
<var name="tmpdb_host" value="(local)\SQL2017" />
<var name="tmpdb_username" value="sa" />
<var name="tmpdb_password" value="Password12!" />
<var name="tmpdb_port" value="1433"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -11,18 +11,11 @@ ...@@ -11,18 +11,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="sqlsrv"/> <var name="db_driver" value="sqlsrv"/>
<var name="db_host" value="(local)\SQL2017" /> <var name="db_host" value="(local)\SQL2017" />
<var name="db_username" value="sa" /> <var name="db_user" value="sa" />
<var name="db_password" value="Password12!" /> <var name="db_password" value="Password12!" />
<var name="db_name" value="doctrine_tests" /> <var name="db_dbname" value="doctrine_tests" />
<var name="db_port" value="1433" />
<var name="tmpdb_type" value="sqlsrv"/>
<var name="tmpdb_host" value="(local)\SQL2017" />
<var name="tmpdb_username" value="sa" />
<var name="tmpdb_password" value="Password12!" />
<var name="tmpdb_port" value="1433" />
</php> </php>
<testsuites> <testsuites>
......
...@@ -11,20 +11,18 @@ ...@@ -11,20 +11,18 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="oci8"/> <var name="db_driver" value="oci8"/>
<var name="db_host" value="oracle-xe-11" /> <var name="db_host" value="oracle-xe-11" />
<var name="db_username" value="C##doctrine" /> <var name="db_user" value="C##doctrine" />
<var name="db_password" value="ORACLE" /> <var name="db_password" value="ORACLE" />
<var name="db_name" value="XE" /> <var name="db_dbname" value="XE" />
<var name="db_port" value="1521"/>
<var name="db_event_subscribers" value="Doctrine\DBAL\Event\Listeners\OracleSessionInit"/> <var name="db_event_subscribers" value="Doctrine\DBAL\Event\Listeners\OracleSessionInit"/>
<var name="tmpdb_type" value="oci8"/> <var name="tmpdb_driver" value="oci8"/>
<var name="tmpdb_host" value="oracle-xe-11" /> <var name="tmpdb_host" value="oracle-xe-11" />
<var name="tmpdb_username" value="ORACLE" /> <var name="tmpdb_user" value="ORACLE" />
<var name="tmpdb_password" value="ORACLE" /> <var name="tmpdb_password" value="ORACLE" />
<var name="tmpdb_name" value="XE" /> <var name="tmpdb_dbname" value="XE" />
<var name="tmpdb_port" value="1521"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -9,20 +9,18 @@ ...@@ -9,20 +9,18 @@
bootstrap="bootstrap.php" bootstrap="bootstrap.php"
> >
<php> <php>
<var name="db_type" value="pdo_oci"/> <var name="db_driver" value="pdo_oci"/>
<var name="db_host" value="oracle-xe-11" /> <var name="db_host" value="oracle-xe-11" />
<var name="db_username" value="C##doctrine" /> <var name="db_user" value="C##doctrine" />
<var name="db_password" value="ORACLE" /> <var name="db_password" value="ORACLE" />
<var name="db_name" value="XE" /> <var name="db_dbname" value="XE" />
<var name="db_port" value="1521"/>
<var name="db_event_subscribers" value="Doctrine\DBAL\Event\Listeners\OracleSessionInit"/> <var name="db_event_subscribers" value="Doctrine\DBAL\Event\Listeners\OracleSessionInit"/>
<var name="tmpdb_type" value="pdo_oci"/> <var name="tmpdb_driver" value="pdo_oci"/>
<var name="tmpdb_host" value="oracle-xe-11" /> <var name="tmpdb_host" value="oracle-xe-11" />
<var name="tmpdb_username" value="ORACLE" /> <var name="tmpdb_user" value="ORACLE" />
<var name="tmpdb_password" value="ORACLE" /> <var name="tmpdb_password" value="ORACLE" />
<var name="tmpdb_name" value="XE" /> <var name="tmpdb_dbname" value="XE" />
<var name="tmpdb_port" value="1521"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -10,19 +10,11 @@ ...@@ -10,19 +10,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="ibm_db2"/> <var name="db_driver" value="ibm_db2"/>
<var name="db_host" value="127.0.0.1"/> <var name="db_host" value="127.0.0.1"/>
<var name="db_username" value="db2inst1"/> <var name="db_user" value="db2inst1"/>
<var name="db_password" value="Doctrine2018"/> <var name="db_password" value="Doctrine2018"/>
<var name="db_name" value="HOSTNAME=127.0.0.1;UID=db2inst1;PWD=Doctrine2018;DATABASE=doctrine"/> <var name="db_dbname" value="doctrine"/>
<var name="db_port" value="50000"/>
<var name="tmpdb_type" value="ibm_db2"/>
<var name="tmpdb_host" value="127.0.0.1"/>
<var name="tmpdb_username" value="db2inst1"/>
<var name="tmpdb_password" value="Doctrine2018"/>
<var name="tmpdb_name" value="HOSTNAME=127.0.0.1;UID=db2inst1;PWD=Doctrine2018;DATABASE=doctrine"/>
<var name="tmpdb_port" value="50000"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -10,18 +10,11 @@ ...@@ -10,18 +10,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="pdo_mysql"/> <var name="db_driver" value="pdo_mysql"/>
<var name="db_host" value="127.0.0.1" /> <var name="db_host" value="127.0.0.1" />
<var name="db_username" value="root" />
<var name="db_password" value="" />
<var name="db_name" value="doctrine_tests" />
<var name="db_port" value="33306"/> <var name="db_port" value="33306"/>
<var name="db_user" value="root" />
<var name="tmpdb_type" value="pdo_mysql"/> <var name="db_dbname" value="doctrine_tests" />
<var name="tmpdb_host" value="127.0.0.1" />
<var name="tmpdb_username" value="root" />
<var name="tmpdb_password" value="" />
<var name="tmpdb_port" value="33306"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -10,18 +10,11 @@ ...@@ -10,18 +10,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="mysqli"/> <var name="db_driver" value="mysqli"/>
<var name="db_host" value="127.0.0.1" /> <var name="db_host" value="127.0.0.1" />
<var name="db_username" value="root" />
<var name="db_password" value="" />
<var name="db_name" value="doctrine_tests" />
<var name="db_port" value="33306"/> <var name="db_port" value="33306"/>
<var name="db_user" value="root" />
<var name="tmpdb_type" value="mysqli"/> <var name="db_dbname" value="doctrine_tests" />
<var name="tmpdb_host" value="127.0.0.1" />
<var name="tmpdb_username" value="root" />
<var name="tmpdb_password" value="" />
<var name="tmpdb_port" value="33306"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -10,18 +10,11 @@ ...@@ -10,18 +10,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="pdo_mysql"/> <var name="db_driver" value="pdo_mysql"/>
<var name="db_host" value="127.0.0.1" /> <var name="db_host" value="127.0.0.1" />
<var name="db_username" value="root" />
<var name="db_password" value="" />
<var name="db_name" value="doctrine_tests" />
<var name="db_port" value="33306"/> <var name="db_port" value="33306"/>
<var name="db_user" value="root" />
<var name="tmpdb_type" value="pdo_mysql"/> <var name="db_dbname" value="doctrine_tests" />
<var name="tmpdb_host" value="127.0.0.1" />
<var name="tmpdb_username" value="root" />
<var name="tmpdb_password" value="" />
<var name="tmpdb_port" value="33306"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -10,18 +10,11 @@ ...@@ -10,18 +10,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="mysqli"/> <var name="db_driver" value="mysqli"/>
<var name="db_host" value="127.0.0.1" /> <var name="db_host" value="127.0.0.1" />
<var name="db_username" value="root" />
<var name="db_password" value="" />
<var name="db_name" value="doctrine_tests" />
<var name="db_port" value="33306"/> <var name="db_port" value="33306"/>
<var name="db_user" value="root" />
<var name="tmpdb_type" value="mysqli"/> <var name="db_dbname" value="doctrine_tests" />
<var name="tmpdb_host" value="127.0.0.1" />
<var name="tmpdb_username" value="root" />
<var name="tmpdb_password" value="" />
<var name="tmpdb_port" value="33306"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -10,18 +10,11 @@ ...@@ -10,18 +10,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="pdo_sqlsrv"/> <var name="db_driver" value="pdo_sqlsrv"/>
<var name="db_host" value="127.0.0.1" /> <var name="db_host" value="127.0.0.1" />
<var name="db_username" value="sa" /> <var name="db_user" value="sa" />
<var name="db_password" value="Doctrine2018" /> <var name="db_password" value="Doctrine2018" />
<var name="db_name" value="doctrine" /> <var name="db_dbname" value="doctrine" />
<var name="db_port" value="1433"/>
<var name="tmpdb_type" value="pdo_sqlsrv"/>
<var name="tmpdb_host" value="127.0.0.1" />
<var name="tmpdb_username" value="sa" />
<var name="tmpdb_password" value="Doctrine2018" />
<var name="tmpdb_port" value="1433"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -10,18 +10,10 @@ ...@@ -10,18 +10,10 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="pdo_pgsql"/> <var name="db_driver" value="pdo_pgsql"/>
<var name="db_host" value="localhost" /> <var name="db_host" value="localhost" />
<var name="db_username" value="postgres" /> <var name="db_user" value="postgres" />
<var name="db_password" value="" /> <var name="db_dbname" value="doctrine_tests" />
<var name="db_name" value="doctrine_tests" />
<var name="db_port" value="5432"/>
<var name="tmpdb_type" value="pdo_pgsql"/>
<var name="tmpdb_host" value="localhost" />
<var name="tmpdb_username" value="postgres" />
<var name="tmpdb_password" value="" />
<var name="tmpdb_port" value="5432"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -10,18 +10,11 @@ ...@@ -10,18 +10,11 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<var name="db_type" value="sqlsrv"/> <var name="db_driver" value="sqlsrv"/>
<var name="db_host" value="127.0.0.1" /> <var name="db_host" value="127.0.0.1" />
<var name="db_username" value="sa" /> <var name="db_user" value="sa" />
<var name="db_password" value="Doctrine2018" /> <var name="db_password" value="Doctrine2018" />
<var name="db_name" value="doctrine" /> <var name="db_dbname" value="doctrine" />
<var name="db_port" value="1433"/>
<var name="tmpdb_type" value="sqlsrv"/>
<var name="tmpdb_host" value="127.0.0.1" />
<var name="tmpdb_username" value="sa" />
<var name="tmpdb_password" value="Doctrine2018" />
<var name="tmpdb_port" value="1433"/>
</php> </php>
<testsuites> <testsuites>
......
...@@ -22,24 +22,24 @@ ...@@ -22,24 +22,24 @@
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />
<!-- "Real" test database --> <!-- Test connection parameters -->
<!-- Uncomment, otherwise SQLite runs <!-- Uncomment, otherwise SQLite runs
<var name="db_type" value="pdo_mysql"/> <var name="db_driver" value="pdo_mysql"/>
<var name="db_host" value="localhost" /> <var name="db_host" value="localhost" />
<var name="db_username" value="root" />
<var name="db_password" value="" />
<var name="db_name" value="doctrine_tests" />
<var name="db_port" value="3306"/> <var name="db_port" value="3306"/>
<var name="db_user" value="root" />
<var name="db_password" value="" />
<var name="db_dbname" value="doctrine_tests" />
--> -->
<!--<var name="db_event_subscribers" value="Doctrine\DBAL\Event\Listeners\OracleSessionInit">--> <!--<var name="db_event_subscribers" value="Doctrine\DBAL\Event\Listeners\OracleSessionInit">-->
<!-- Database for temporary connections (i.e. to drop/create the main database) --> <!-- Privileged user connection parameters. Used to create and drop the test database -->
<var name="tmpdb_type" value="pdo_mysql"/> <var name="tmpdb_driver" value="pdo_mysql"/>
<var name="tmpdb_host" value="localhost" /> <var name="tmpdb_host" value="localhost" />
<var name="tmpdb_username" value="root" />
<var name="tmpdb_password" value="" />
<var name="tmpdb_name" value="doctrine_tests_tmp" />
<var name="tmpdb_port" value="3306"/> <var name="tmpdb_port" value="3306"/>
<var name="tmpdb_user" value="root" />
<var name="tmpdb_password" value="" />
<var name="tmpdb_dbname" value="doctrine_tests_tmp" />
</php> </php>
<testsuites> <testsuites>
......
...@@ -53,6 +53,8 @@ interface Driver ...@@ -53,6 +53,8 @@ interface Driver
/** /**
* Gets the name of the database connected to for this driver. * Gets the name of the database connected to for this driver.
* *
* @deprecated Use Connection::getDatabase() instead.
*
* @return string The name of the database. * @return string The name of the database.
*/ */
public function getDatabase(Connection $conn); public function getDatabase(Connection $conn);
......
...@@ -14,6 +14,8 @@ abstract class AbstractDB2Driver implements Driver ...@@ -14,6 +14,8 @@ abstract class AbstractDB2Driver implements Driver
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use Connection::getDatabase() instead.
*/ */
public function getDatabase(Connection $conn) public function getDatabase(Connection $conn)
{ {
......
...@@ -196,6 +196,8 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA ...@@ -196,6 +196,8 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use Connection::getDatabase() instead.
*/ */
public function getDatabase(Connection $conn) public function getDatabase(Connection $conn)
{ {
......
...@@ -59,6 +59,8 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver ...@@ -59,6 +59,8 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use Connection::getDatabase() instead.
*/ */
public function getDatabase(Connection $conn) public function getDatabase(Connection $conn)
{ {
......
...@@ -104,6 +104,8 @@ abstract class AbstractPostgreSQLDriver implements ExceptionConverterDriver, Ver ...@@ -104,6 +104,8 @@ abstract class AbstractPostgreSQLDriver implements ExceptionConverterDriver, Ver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use Connection::getDatabase() instead.
*/ */
public function getDatabase(Connection $conn) public function getDatabase(Connection $conn)
{ {
......
...@@ -103,6 +103,8 @@ abstract class AbstractSQLAnywhereDriver implements ExceptionConverterDriver, Ve ...@@ -103,6 +103,8 @@ abstract class AbstractSQLAnywhereDriver implements ExceptionConverterDriver, Ve
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use Connection::getDatabase() instead.
*/ */
public function getDatabase(Connection $conn) public function getDatabase(Connection $conn)
{ {
......
...@@ -14,6 +14,8 @@ abstract class AbstractSQLServerDriver implements Driver ...@@ -14,6 +14,8 @@ abstract class AbstractSQLServerDriver implements Driver
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use Connection::getDatabase() instead.
*/ */
public function getDatabase(Connection $conn) public function getDatabase(Connection $conn)
{ {
......
...@@ -79,6 +79,8 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver ...@@ -79,6 +79,8 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use Connection::getDatabase() instead.
*/ */
public function getDatabase(Connection $conn) public function getDatabase(Connection $conn)
{ {
......
...@@ -14,27 +14,16 @@ class DB2Driver extends AbstractDB2Driver ...@@ -14,27 +14,16 @@ class DB2Driver extends AbstractDB2Driver
*/ */
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{ {
if (! isset($params['protocol'])) { $params['user'] = $username;
$params['protocol'] = 'TCPIP'; $params['password'] = $password;
} $params['dbname'] = DataSourceName::fromConnectionParameters($params)->toString();
if ($params['host'] !== 'localhost' && $params['host'] !== '127.0.0.1') { return new DB2Connection(
// if the host isn't localhost, use extended connection params $params,
$params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' . (string) $username,
';DATABASE=' . $params['dbname'] . (string) $password,
';HOSTNAME=' . $params['host'] . $driverOptions
';PROTOCOL=' . $params['protocol'] . );
';UID=' . $username .
';PWD=' . $password . ';';
if (isset($params['port'])) {
$params['dbname'] .= 'PORT=' . $params['port'];
}
$username = null;
$password = null;
}
return new DB2Connection($params, (string) $username, (string) $password, $driverOptions);
} }
/** /**
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\IBMDB2;
use function implode;
use function sprintf;
use function strpos;
/**
* IBM DB2 DSN
*/
final class DataSourceName
{
/** @var string */
private $string;
private function __construct(string $string)
{
$this->string = $string;
}
public function toString(): string
{
return $this->string;
}
/**
* Creates the object from an array representation
*
* @param array<string,mixed> $params
*/
public static function fromArray(array $params): self
{
$chunks = [];
foreach ($params as $key => $value) {
$chunks[] = sprintf('%s=%s', $key, $value);
}
return new self(implode(';', $chunks));
}
/**
* Creates the object from the given DBAL connection parameters.
*
* @param array<string,mixed> $params
*/
public static function fromConnectionParameters(array $params): self
{
if (isset($params['dbname']) && strpos($params['dbname'], '=') !== false) {
return new self($params['dbname']);
}
$dsnParams = [];
foreach (
[
'host' => 'HOSTNAME',
'port' => 'PORT',
'protocol' => 'PROTOCOL',
'dbname' => 'DATABASE',
'user' => 'UID',
'password' => 'PWD',
] as $dbalParam => $dsnParam
) {
if (! isset($params[$dbalParam])) {
continue;
}
$dsnParams[$dsnParam] = $params[$dbalParam];
}
return self::fromArray($dsnParams);
}
}
<?php
namespace Doctrine\Tests\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\IBMDB2\DataSourceName;
use PHPUnit\Framework\TestCase;
class DataSourceNameTest extends TestCase
{
/**
* @param mixed[] $params
*
* @dataProvider connectionParametersProvider
*/
public function testFromConnectionParameters(array $params, string $expected): void
{
$dsn = DataSourceName::fromConnectionParameters($params);
$this->assertSame($expected, $dsn->toString());
}
/**
* @return iterable<string,array<int,mixed>>
*/
public static function connectionParametersProvider(): iterable
{
yield 'empty-params' => [[], ''];
yield 'cataloged-database' => [
[
'host' => 'localhost',
'port' => 50000,
'dbname' => 'doctrine',
'user' => 'db2inst1',
'password' => 'Passw0rd',
],
'HOSTNAME=localhost;PORT=50000;DATABASE=doctrine;UID=db2inst1;PWD=Passw0rd',
];
yield 'uncataloged-database' => [
['dbname' => 'HOSTNAME=localhost;PORT=50000;DATABASE=doctrine;UID=db2inst1;PWD=Passw0rd'],
'HOSTNAME=localhost;PORT=50000;DATABASE=doctrine;UID=db2inst1;PWD=Passw0rd',
];
}
}
...@@ -6,11 +6,10 @@ use Doctrine\DBAL\Driver as DriverInterface; ...@@ -6,11 +6,10 @@ use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\DBAL\Driver\PDOPgSql\Driver;
use Doctrine\DBAL\Tests\Driver\AbstractPostgreSQLDriverTest; use Doctrine\DBAL\Tests\Driver\AbstractPostgreSQLDriverTest;
use Doctrine\DBAL\Tests\TestUtil;
use PDO; use PDO;
use PDOException; use PDOException;
use function defined;
class DriverTest extends AbstractPostgreSQLDriverTest class DriverTest extends AbstractPostgreSQLDriverTest
{ {
public function testReturnsName(): void public function testReturnsName(): void
...@@ -23,18 +22,9 @@ class DriverTest extends AbstractPostgreSQLDriverTest ...@@ -23,18 +22,9 @@ class DriverTest extends AbstractPostgreSQLDriverTest
*/ */
public function testConnectionDisablesPreparesOnPhp56(): void public function testConnectionDisablesPreparesOnPhp56(): void
{ {
$this->skipWhenNotUsingPhp56AndPdoPgsql(); $this->skipWhenNotUsingPdoPgsql();
$connection = $this->createDriver()->connect(
[
'host' => $GLOBALS['db_host'],
'port' => $GLOBALS['db_port'],
],
$GLOBALS['db_username'],
$GLOBALS['db_password']
);
self::assertInstanceOf(PDOConnection::class, $connection); $connection = $this->connect([]);
try { try {
self::assertTrue($connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); self::assertTrue($connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES));
...@@ -49,20 +39,12 @@ class DriverTest extends AbstractPostgreSQLDriverTest ...@@ -49,20 +39,12 @@ class DriverTest extends AbstractPostgreSQLDriverTest
*/ */
public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined(): void public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined(): void
{ {
$this->skipWhenNotUsingPhp56AndPdoPgsql(); $this->skipWhenNotUsingPdoPgsql();
$connection = $this->createDriver()->connect( $connection = $this->connect(
[
'host' => $GLOBALS['db_host'],
'port' => $GLOBALS['db_port'],
],
$GLOBALS['db_username'],
$GLOBALS['db_password'],
[PDO::PGSQL_ATTR_DISABLE_PREPARES => false] [PDO::PGSQL_ATTR_DISABLE_PREPARES => false]
); );
self::assertInstanceOf(PDOConnection::class, $connection);
try { try {
self::assertNotSame( self::assertNotSame(
true, true,
...@@ -79,20 +61,12 @@ class DriverTest extends AbstractPostgreSQLDriverTest ...@@ -79,20 +61,12 @@ class DriverTest extends AbstractPostgreSQLDriverTest
*/ */
public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined(): void public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined(): void
{ {
$this->skipWhenNotUsingPhp56AndPdoPgsql(); $this->skipWhenNotUsingPdoPgsql();
$connection = $this->createDriver()->connect( $connection = $this->connect(
[
'host' => $GLOBALS['db_host'],
'port' => $GLOBALS['db_port'],
],
$GLOBALS['db_username'],
$GLOBALS['db_password'],
[PDO::PGSQL_ATTR_DISABLE_PREPARES => true] [PDO::PGSQL_ATTR_DISABLE_PREPARES => true]
); );
self::assertInstanceOf(PDOConnection::class, $connection);
try { try {
self::assertTrue($connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); self::assertTrue($connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES));
} catch (PDOException $ignored) { } catch (PDOException $ignored) {
...@@ -106,16 +80,27 @@ class DriverTest extends AbstractPostgreSQLDriverTest ...@@ -106,16 +80,27 @@ class DriverTest extends AbstractPostgreSQLDriverTest
return new Driver(); return new Driver();
} }
private function skipWhenNotUsingPhp56AndPdoPgsql(): void private function skipWhenNotUsingPdoPgsql(): void
{ {
if (! defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) { if (isset($GLOBALS['db_driver']) && $GLOBALS['db_driver'] === 'pdo_pgsql') {
$this->markTestSkipped('Test requires PHP 5.6+');
}
if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql') {
return; return;
} }
$this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml');
} }
/**
* @param array<int,mixed> $driverOptions
*/
private function connect(array $driverOptions): PDOConnection
{
$params = TestUtil::getConnectionParams();
return $this->createDriver()->connect(
$params,
$params['user'] ?? '',
$params['password'] ?? '',
$driverOptions
);
}
} }
...@@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\Mysqli\Driver; ...@@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\Mysqli\Driver;
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection; use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
use Doctrine\DBAL\Driver\Mysqli\MysqliException; use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use function extension_loaded; use function extension_loaded;
...@@ -57,14 +58,12 @@ class ConnectionTest extends FunctionalTestCase ...@@ -57,14 +58,12 @@ class ConnectionTest extends FunctionalTestCase
*/ */
private function getConnection(array $driverOptions): MysqliConnection private function getConnection(array $driverOptions): MysqliConnection
{ {
$params = TestUtil::getConnectionParams();
return new MysqliConnection( return new MysqliConnection(
[ $params,
'host' => $GLOBALS['db_host'], $params['user'] ?? '',
'dbname' => $GLOBALS['db_name'], $params['password'] ?? '',
'port' => $GLOBALS['db_port'],
],
$GLOBALS['db_username'],
$GLOBALS['db_password'],
$driverOptions $driverOptions
); );
} }
......
...@@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver\Connection; ...@@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest; use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
use Doctrine\DBAL\Tests\TestUtil;
use PDO; use PDO;
use function assert; use function assert;
...@@ -45,13 +46,12 @@ class DriverTest extends AbstractDriverTest ...@@ -45,13 +46,12 @@ class DriverTest extends AbstractDriverTest
*/ */
protected function getConnection(array $driverOptions): Connection protected function getConnection(array $driverOptions): Connection
{ {
$params = TestUtil::getConnectionParams();
return $this->connection->getDriver()->connect( return $this->connection->getDriver()->connect(
[ $params,
'host' => $GLOBALS['db_host'], $params['user'] ?? '',
'port' => $GLOBALS['db_port'], $params['password'] ?? '',
],
$GLOBALS['db_username'],
$GLOBALS['db_password'],
$driverOptions $driverOptions
); );
} }
......
...@@ -23,12 +23,12 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -23,12 +23,12 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
return; return;
} }
if (! isset($GLOBALS['db_username'])) { if (! isset($GLOBALS['db_user'])) {
self::markTestSkipped('Username must be explicitly specified in connection parameters for this test'); self::markTestSkipped('Username must be explicitly specified in connection parameters for this test');
} }
TestUtil::getTempConnection() TestUtil::getPrivilegedConnection()
->exec('GRANT ALL PRIVILEGES TO ' . $GLOBALS['db_username']); ->exec('GRANT ALL PRIVILEGES TO ' . $GLOBALS['db_user']);
self::$privilegesGranted = true; self::$privilegesGranted = true;
} }
...@@ -105,8 +105,8 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -105,8 +105,8 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
public function testListDatabases(): void public function testListDatabases(): void
{ {
// We need the temp connection that has privileges to create a database. // We need a privileged connection to create the database.
$sm = TestUtil::getTempConnection()->getSchemaManager(); $sm = TestUtil::getPrivilegedConnection()->getSchemaManager();
$sm->dropAndCreateDatabase('c##test_create_database'); $sm->dropAndCreateDatabase('c##test_create_database');
...@@ -234,7 +234,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -234,7 +234,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$otherTable = new Table($table->getName()); $otherTable = new Table($table->getName());
$otherTable->addColumn('id', Types::STRING); $otherTable->addColumn('id', Types::STRING);
TestUtil::getTempConnection()->getSchemaManager()->dropAndCreateTable($otherTable); TestUtil::getPrivilegedConnection()->getSchemaManager()->dropAndCreateTable($otherTable);
$columns = $this->schemaManager->listTableColumns($table->getName(), $this->connection->getUsername()); $columns = $this->schemaManager->listTableColumns($table->getName(), $this->connection->getUsername());
self::assertCount(7, $columns); self::assertCount(7, $columns);
......
...@@ -25,24 +25,22 @@ class TestUtil ...@@ -25,24 +25,22 @@ class TestUtil
private static $initialized = false; private static $initialized = false;
/** /**
* Gets a <b>real</b> database connection using the following parameters * Creates a new <b>test</b> database connection using the following parameters
* of the $GLOBALS array: * of the $GLOBALS array:
* *
* 'db_type' : The name of the Doctrine DBAL database driver to use. * 'db_driver': The name of the Doctrine DBAL database driver to use.
* 'db_username' : The username to use for connecting. * 'db_user': The username to use for connecting.
* 'db_password' : The password to use for connecting. * 'db_password': The password to use for connecting.
* 'db_host' : The hostname of the database to connect to. * 'db_host': The hostname of the database to connect to.
* 'db_server' : The server name of the database to connect to * 'db_server': The server name of the database to connect to
* (optional, some vendors allow multiple server instances with different names on the same host). * (optional, some vendors allow multiple server instances with different names on the same host).
* 'db_name' : The name of the database to connect to. * 'db_dbname': The name of the database to connect to.
* 'db_port' : The port of the database to connect to. * 'db_port': The port of the database to connect to.
* *
* Usually these variables of the $GLOBALS array are filled by PHPUnit based * Usually these variables of the $GLOBALS array are filled by PHPUnit based
* on an XML configuration file. If no such parameters exist, an SQLite * on an XML configuration file. If no such parameters exist, an SQLite
* in-memory database is used. * in-memory database is used.
* *
* IMPORTANT: Each invocation of this method returns a NEW database connection.
*
* @return Connection The database connection instance. * @return Connection The database connection instance.
*/ */
public static function getConnection(): Connection public static function getConnection(): Connection
...@@ -65,7 +63,7 @@ class TestUtil ...@@ -65,7 +63,7 @@ class TestUtil
public static function getConnectionParams(): array public static function getConnectionParams(): array
{ {
if (self::hasRequiredConnectionParams()) { if (self::hasRequiredConnectionParams()) {
return self::getParamsForMainConnection(); return self::getTestConnectionParameters();
} }
return self::getFallbackConnectionParams(); return self::getFallbackConnectionParams();
...@@ -73,50 +71,36 @@ class TestUtil ...@@ -73,50 +71,36 @@ class TestUtil
private static function hasRequiredConnectionParams(): bool private static function hasRequiredConnectionParams(): bool
{ {
return isset( return isset($GLOBALS['db_driver']);
$GLOBALS['db_type'],
$GLOBALS['db_username'],
$GLOBALS['db_password'],
$GLOBALS['db_host'],
$GLOBALS['db_name'],
$GLOBALS['db_port']
)
&& isset(
$GLOBALS['tmpdb_type'],
$GLOBALS['tmpdb_username'],
$GLOBALS['tmpdb_password'],
$GLOBALS['tmpdb_host'],
$GLOBALS['tmpdb_port']
);
} }
private static function initializeDatabase(): void private static function initializeDatabase(): void
{ {
$realDbParams = self::getParamsForMainConnection(); $testConnParams = self::getTestConnectionParameters();
$tmpDbParams = self::getParamsForTemporaryConnection(); $privConnParams = self::getPrivilegedConnectionParameters();
$realConn = DriverManager::getConnection($realDbParams); $testConn = DriverManager::getConnection($testConnParams);
// Connect to tmpdb in order to drop and create the real test db. // Connect as a privileged user to create and drop the test database.
$tmpConn = DriverManager::getConnection($tmpDbParams); $privConn = DriverManager::getConnection($privConnParams);
$platform = $tmpConn->getDatabasePlatform(); $platform = $privConn->getDatabasePlatform();
if ($platform->supportsCreateDropDatabase()) { if ($platform->supportsCreateDropDatabase()) {
$dbname = $realConn->getDatabase(); $dbname = $testConn->getDatabase();
$realConn->close(); $testConn->close();
$tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname); $privConn->getSchemaManager()->dropAndCreateDatabase($dbname);
$tmpConn->close(); $privConn->close();
} else { } else {
$sm = $realConn->getSchemaManager(); $sm = $testConn->getSchemaManager();
$schema = $sm->createSchema(); $schema = $sm->createSchema();
$stmts = $schema->toDropSql($realConn->getDatabasePlatform()); $stmts = $schema->toDropSql($testConn->getDatabasePlatform());
foreach ($stmts as $stmt) { foreach ($stmts as $stmt) {
$realConn->exec($stmt); $testConn->exec($stmt);
} }
} }
} }
...@@ -159,60 +143,60 @@ class TestUtil ...@@ -159,60 +143,60 @@ class TestUtil
/** /**
* @return mixed[] * @return mixed[]
*/ */
private static function getParamsForTemporaryConnection(): array private static function getPrivilegedConnectionParameters(): array
{ {
$connectionParams = [ if (isset($GLOBALS['tmpdb_driver'])) {
'driver' => $GLOBALS['tmpdb_type'], return self::mapConnectionParameters($GLOBALS, 'tmpdb_');
'user' => $GLOBALS['tmpdb_username'],
'password' => $GLOBALS['tmpdb_password'],
'host' => $GLOBALS['tmpdb_host'],
'dbname' => null,
'port' => $GLOBALS['tmpdb_port'],
];
if (isset($GLOBALS['tmpdb_name'])) {
$connectionParams['dbname'] = $GLOBALS['tmpdb_name'];
} }
if (isset($GLOBALS['tmpdb_server'])) { $parameters = self::mapConnectionParameters($GLOBALS, 'db_');
$connectionParams['server'] = $GLOBALS['tmpdb_server']; unset($parameters['dbname']);
}
if (isset($GLOBALS['tmpdb_unix_socket'])) { return $parameters;
$connectionParams['unix_socket'] = $GLOBALS['tmpdb_unix_socket'];
}
return $connectionParams;
} }
/** /**
* @return mixed[] * @return mixed[]
*/ */
private static function getParamsForMainConnection(): array private static function getTestConnectionParameters(): array
{ {
$connectionParams = [ return self::mapConnectionParameters($GLOBALS, 'db_');
'driver' => $GLOBALS['db_type'], }
'user' => $GLOBALS['db_username'],
'password' => $GLOBALS['db_password'],
'host' => $GLOBALS['db_host'],
'dbname' => $GLOBALS['db_name'],
'port' => $GLOBALS['db_port'],
];
if (isset($GLOBALS['db_server'])) { /**
$connectionParams['server'] = $GLOBALS['db_server']; * @param array<string,mixed> $configuration
} *
* @return array<string,mixed>
*/
private static function mapConnectionParameters(array $configuration, string $prefix): array
{
$parameters = [];
foreach (
[
'driver',
'user',
'password',
'host',
'dbname',
'port',
'server',
'unix_socket',
] as $parameter
) {
if (! isset($configuration[$prefix . $parameter])) {
continue;
}
if (isset($GLOBALS['db_unix_socket'])) { $parameters[$parameter] = $configuration[$prefix . $parameter];
$connectionParams['unix_socket'] = $GLOBALS['db_unix_socket'];
} }
return $connectionParams; return $parameters;
} }
public static function getTempConnection(): Connection public static function getPrivilegedConnection(): Connection
{ {
return DriverManager::getConnection(self::getParamsForTemporaryConnection()); return DriverManager::getConnection(self::getPrivilegedConnectionParameters());
} }
/** /**
......
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