Skip to content

Commit

Permalink
[DBAL-2648] Close temporary connection to eliminate the leak (1 of 2 …
Browse files Browse the repository at this point in the history
…handles per test)
  • Loading branch information
morozov committed Apr 3, 2018
1 parent a77eec4 commit 5746e9f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions tests/Doctrine/Tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Tests;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\DriverManager;
use PHPUnit\Framework\Assert;
use function explode;
Expand Down Expand Up @@ -78,25 +79,27 @@ private static function hasRequiredConnectionParams()
);
}

private static function getSpecifiedConnectionParams() {
/**
* @return string[]
* @throws DBALException
*/
private static function getSpecifiedConnectionParams() : array
{
$realDbParams = self::getParamsForMainConnection();
$tmpDbParams = self::getParamsForTemporaryConnection();

$realConn = DriverManager::getConnection($realDbParams);

// Connect to tmpdb in order to drop and create the real test db.
$tmpConn = DriverManager::getConnection($tmpDbParams);

$platform = $tmpConn->getDatabasePlatform();

if (! self::$initialized) {
// Connect to the temporary DB in order to drop and create the real test one
$tmpConn = DriverManager::getConnection($tmpDbParams);
$platform = $tmpConn->getDatabasePlatform();

if ($platform->supportsCreateDropDatabase()) {
$dbname = $realConn->getDatabase();
$realConn->close();

$tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname);

$tmpConn->close();
} else {
$sm = $realConn->getSchemaManager();

Expand All @@ -108,6 +111,8 @@ private static function getSpecifiedConnectionParams() {
}
}

$tmpConn->close();

self::$initialized = true;
}

Expand Down

0 comments on commit 5746e9f

Please sign in to comment.