Unverified Commit 2080599b authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #3473 from morozov/issues/3471

Avoid database connection from PHPUnit data providers
parents 6a9edc9f 8a1b0a2d
......@@ -55,7 +55,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
);
self::assertSame(
$this->getDatabaseNameForConnectionWithoutDatabaseNameParameter(),
static::getDatabaseNameForConnectionWithoutDatabaseNameParameter(),
$this->driver->getDatabase($connection)
);
}
......@@ -65,10 +65,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
*/
abstract protected function createDriver();
/**
* @return string|null
*/
protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter()
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return null;
}
......
......@@ -50,9 +50,12 @@ class DriverTest extends AbstractDriverTest
);
}
public function getDatabaseParameter()
/**
* @return mixed[][]
*/
public static function getDatabaseParameter() : iterable
{
$params = TestUtil::getConnection()->getParams();
$params = TestUtil::getConnectionParams();
$realDatabaseName = $params['dbname'] ?? '';
$dummyDatabaseName = $realDatabaseName . 'a';
......@@ -61,7 +64,7 @@ class DriverTest extends AbstractDriverTest
[$realDatabaseName, null, $realDatabaseName],
[$realDatabaseName, $dummyDatabaseName, $realDatabaseName],
[null, $realDatabaseName, $realDatabaseName],
[null, null, $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter()],
[null, null, static::getDatabaseNameForConnectionWithoutDatabaseNameParameter()],
];
}
......@@ -108,7 +111,7 @@ class DriverTest extends AbstractDriverTest
/**
* {@inheritdoc}
*/
protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter()
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return 'postgres';
}
......
......@@ -36,7 +36,7 @@ class DriverTest extends AbstractDriverTest
/**
* {@inheritdoc}
*/
protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter()
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return 'master';
}
......
......@@ -34,7 +34,7 @@ class DriverTest extends AbstractDriverTest
/**
* {@inheritdoc}
*/
protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter()
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return 'master';
}
......
......@@ -40,6 +40,11 @@ class TestUtil
*/
public static function getConnection()
{
if (self::hasRequiredConnectionParams() && ! self::$initialized) {
self::initializeDatabase();
self::$initialized = true;
}
$conn = DriverManager::getConnection(self::getConnectionParams());
self::addDbEventSubscribers($conn);
......@@ -47,10 +52,10 @@ class TestUtil
return $conn;
}
private static function getConnectionParams()
public static function getConnectionParams()
{
if (self::hasRequiredConnectionParams()) {
return self::getSpecifiedConnectionParams();
return self::getParamsForMainConnection();
}
return self::getFallbackConnectionParams();
......@@ -75,7 +80,7 @@ class TestUtil
);
}
private static function getSpecifiedConnectionParams()
private static function initializeDatabase() : void
{
$realDbParams = self::getParamsForMainConnection();
$tmpDbParams = self::getParamsForTemporaryConnection();
......@@ -87,7 +92,6 @@ class TestUtil
$platform = $tmpConn->getDatabasePlatform();
if (! self::$initialized) {
if ($platform->supportsCreateDropDatabase()) {
$dbname = $realConn->getDatabase();
$realConn->close();
......@@ -105,11 +109,6 @@ class TestUtil
$realConn->exec($stmt);
}
}
self::$initialized = true;
}
return $realDbParams;
}
private static function getFallbackConnectionParams()
......
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