Commit 907513f3 authored by Tiago Brito's avatar Tiago Brito

Merge pull request #3 from doctrine/master

Update from master repository
parents 7b29bd53 663135d5
...@@ -20,7 +20,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -20,7 +20,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer', array()); $table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) { foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
...@@ -46,10 +46,10 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -46,10 +46,10 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
$this->setExpectedException('\Doctrine\DBAL\Exception\TableExistsException'); $this->setExpectedException('\Doctrine\DBAL\Exception\TableExistsException');
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) { foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) { foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
} }
...@@ -72,7 +72,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -72,7 +72,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$owningTable->setPrimaryKey(array('id')); $owningTable->setPrimaryKey(array('id'));
$owningTable->addForeignKeyConstraint($table, array('constraint_id'), array('id')); $owningTable->addForeignKeyConstraint($table, array('constraint_id'), array('id'));
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
...@@ -92,7 +92,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -92,7 +92,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('value', 'integer', array('notnull' => true)); $table->addColumn('value', 'integer', array('notnull' => true));
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
...@@ -107,7 +107,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -107,7 +107,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table = $schema->createTable("bad_fieldname_table"); $table = $schema->createTable("bad_fieldname_table");
$table->addColumn('id', 'integer', array()); $table->addColumn('id', 'integer', array());
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
...@@ -125,7 +125,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -125,7 +125,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table2 = $schema->createTable("ambiguous_list_table_2"); $table2 = $schema->createTable("ambiguous_list_table_2");
$table2->addColumn('id', 'integer'); $table2->addColumn('id', 'integer');
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
...@@ -142,7 +142,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -142,7 +142,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer'); $table->addColumn('id', 'integer');
$table->addUniqueIndex(array('id')); $table->addUniqueIndex(array('id'));
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
...@@ -157,7 +157,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -157,7 +157,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer', array()); $table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) { foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
...@@ -195,7 +195,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -195,7 +195,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer'); $table->addColumn('id', 'integer');
$this->setExpectedException($exceptionClass); $this->setExpectedException($exceptionClass);
foreach ($schema->toSql($conn->getDatabasePlatform()) AS $sql) { foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
$conn->executeQuery($sql); $conn->executeQuery($sql);
} }
} }
...@@ -236,7 +236,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -236,7 +236,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->setExpectedException('Doctrine\DBAL\Exception\ConnectionException'); $this->setExpectedException('Doctrine\DBAL\Exception\ConnectionException');
foreach ($schema->toSql($conn->getDatabasePlatform()) AS $sql) { foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
$conn->executeQuery($sql); $conn->executeQuery($sql);
} }
} }
......
...@@ -116,7 +116,7 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -116,7 +116,7 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
{ {
$p = $this->_conn->getDatabasePlatform(); $p = $this->_conn->getDatabasePlatform();
$data = array(); $data = array();
foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) AS $row) { foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) as $row) {
$row = array_change_key_case($row, CASE_LOWER); $row = array_change_key_case($row, CASE_LOWER);
$data[] = $row['test_int']; $data[] = $row['test_int'];
} }
......
...@@ -109,7 +109,7 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -109,7 +109,7 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function assertFetchResultRows($rows) public function assertFetchResultRows($rows)
{ {
$this->assertEquals(2, count($rows)); $this->assertEquals(2, count($rows));
foreach ($rows AS $row) { foreach ($rows as $row) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
} }
......
...@@ -31,7 +31,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -31,7 +31,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
} }
$this->_conn->executeUpdate('DELETE FROM caching'); $this->_conn->executeUpdate('DELETE FROM caching');
foreach ($this->expectedResult AS $row) { foreach ($this->expectedResult as $row) {
$this->_conn->insert('caching', $row); $this->_conn->insert('caching', $row);
} }
...@@ -50,7 +50,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -50,7 +50,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testFetchNum() public function testFetchNum()
{ {
$expectedResult = array(); $expectedResult = array();
foreach ($this->expectedResult AS $v) { foreach ($this->expectedResult as $v) {
$expectedResult[] = array_values($v); $expectedResult[] = array_values($v);
} }
$this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_NUM); $this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_NUM);
...@@ -59,7 +59,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -59,7 +59,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testFetchBoth() public function testFetchBoth()
{ {
$expectedResult = array(); $expectedResult = array();
foreach ($this->expectedResult AS $v) { foreach ($this->expectedResult as $v) {
$expectedResult[] = array_merge($v, array_values($v)); $expectedResult[] = array_merge($v, array_values($v));
} }
$this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_BOTH); $this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_BOTH);
...@@ -68,7 +68,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -68,7 +68,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testFetchColumn() public function testFetchColumn()
{ {
$expectedResult = array(); $expectedResult = array();
foreach ($this->expectedResult AS $v) { foreach ($this->expectedResult as $v) {
$expectedResult[] = array_shift($v); $expectedResult[] = array_shift($v);
} }
$this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_COLUMN); $this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_COLUMN);
...@@ -77,7 +77,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -77,7 +77,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testMixingFetch() public function testMixingFetch()
{ {
$numExpectedResult = array(); $numExpectedResult = array();
foreach ($this->expectedResult AS $v) { foreach ($this->expectedResult as $v) {
$numExpectedResult[] = array_values($v); $numExpectedResult[] = array_values($v);
} }
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
......
...@@ -69,7 +69,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -69,7 +69,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertInternalType('array', $sequences, 'listSequences() should return an array.'); $this->assertInternalType('array', $sequences, 'listSequences() should return an array.');
$foundSequence = null; $foundSequence = null;
foreach($sequences AS $sequence) { foreach($sequences as $sequence) {
$this->assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $sequence, 'Array elements of listSequences() should be Sequence instances.'); $this->assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $sequence, 'Array elements of listSequences() should be Sequence instances.');
if(strtolower($sequence->getName()) == 'list_sequences_test_seq') { if(strtolower($sequence->getName()) == 'list_sequences_test_seq') {
$foundSequence = $sequence; $foundSequence = $sequence;
...@@ -104,7 +104,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -104,7 +104,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertTrue(count($tables) > 0, "List Tables has to find at least one table named 'list_tables_test'."); $this->assertTrue(count($tables) > 0, "List Tables has to find at least one table named 'list_tables_test'.");
$foundTable = false; $foundTable = false;
foreach ($tables AS $table) { foreach ($tables as $table) {
$this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table); $this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table);
if (strtolower($table->getName()) == 'list_tables_test') { if (strtolower($table->getName()) == 'list_tables_test') {
$foundTable = true; $foundTable = true;
...@@ -722,7 +722,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -722,7 +722,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
protected function assertHasTable($tables, $tableName) protected function assertHasTable($tables, $tableName)
{ {
$foundTable = false; $foundTable = false;
foreach ($tables AS $table) { foreach ($tables as $table) {
$this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.'); $this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.');
if (strtolower($table->getName()) == 'list_tables_test_new_name') { if (strtolower($table->getName()) == 'list_tables_test_new_name') {
$foundTable = true; $foundTable = true;
......
...@@ -50,7 +50,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -50,7 +50,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn("id", "integer"); $table->addColumn("id", "integer");
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($platform->getCreateTableSQL($table) AS $sql) { foreach ($platform->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
...@@ -87,7 +87,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -87,7 +87,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn("id", "integer"); $table->addColumn("id", "integer");
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($platform->getCreateTableSQL($table) AS $sql) { foreach ($platform->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
......
...@@ -36,7 +36,7 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -36,7 +36,7 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
try { try {
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) { foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
} catch(\Exception $e) { } catch(\Exception $e) {
......
...@@ -18,7 +18,7 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -18,7 +18,7 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('test_string', 'string', array('notnull' => false)); $table->addColumn('test_string', 'string', array('notnull' => false));
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) { foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
} catch(\Exception $e) { } catch(\Exception $e) {
......
...@@ -55,7 +55,7 @@ class MySQLSchemaTest extends \PHPUnit_Framework_TestCase ...@@ -55,7 +55,7 @@ class MySQLSchemaTest extends \PHPUnit_Framework_TestCase
$tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id')); $tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id'));
$sqls = array(); $sqls = array();
foreach ($tableOld->getForeignKeys() AS $fk) { foreach ($tableOld->getForeignKeys() as $fk) {
$sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld); $sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld);
} }
......
...@@ -49,7 +49,7 @@ class DbalFunctionalTestCase extends DbalTestCase ...@@ -49,7 +49,7 @@ class DbalFunctionalTestCase extends DbalTestCase
if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) {
$queries = ""; $queries = "";
$i = count($this->_sqlLoggerStack->queries); $i = count($this->_sqlLoggerStack->queries);
foreach (array_reverse($this->_sqlLoggerStack->queries) AS $query) { foreach (array_reverse($this->_sqlLoggerStack->queries) as $query) {
$params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array()); $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array());
$queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; $queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL;
$i--; $i--;
...@@ -57,7 +57,7 @@ class DbalFunctionalTestCase extends DbalTestCase ...@@ -57,7 +57,7 @@ class DbalFunctionalTestCase extends DbalTestCase
$trace = $e->getTrace(); $trace = $e->getTrace();
$traceMsg = ""; $traceMsg = "";
foreach($trace AS $part) { foreach($trace as $part) {
if(isset($part['file'])) { if(isset($part['file'])) {
if(strpos($part['file'], "PHPUnit/") !== false) { if(strpos($part['file'], "PHPUnit/") !== false) {
// Beginning with PHPUnit files we don't print the trace anymore. // Beginning with PHPUnit files we don't print the trace anymore.
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\Tests; namespace Doctrine\Tests;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
/** /**
...@@ -32,61 +33,23 @@ class TestUtil ...@@ -32,61 +33,23 @@ class TestUtil
* 1) Each invocation of this method returns a NEW database connection. * 1) Each invocation of this method returns a NEW database connection.
* 2) The database is dropped and recreated to ensure it's clean. * 2) The database is dropped and recreated to ensure it's clean.
* *
* @return \Doctrine\DBAL\Connection The database connection instance. * @return Connection The database connection instance.
*/ */
public static function getConnection() public static function getConnection()
{ {
if (self::hasRequiredConnectionParams()) { $conn = DriverManager::getConnection(self::getConnectionParams());
$realDbParams = self::getConnectionParams();
$tmpDbParams = self::getTmpConnectionParams();
$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 ($platform->supportsCreateDropDatabase()) {
$dbname = $realConn->getDatabase();
$realConn->close();
$tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname);
$tmpConn->close();
} else {
$sm = $realConn->getSchemaManager();
$schema = $sm->createSchema(); self::addDbEventSubscribers($conn);
$stmts = $schema->toDropSql($realConn->getDatabasePlatform());
foreach ($stmts AS $stmt) { return $conn;
$realConn->exec($stmt); }
}
}
$conn = DriverManager::getConnection($realDbParams, null, null);
} else {
$params = array(
'driver' => 'pdo_sqlite',
'memory' => true
);
if (isset($GLOBALS['db_path'])) {
$params['path'] = $GLOBALS['db_path'];
unlink($GLOBALS['db_path']);
}
$conn = DriverManager::getConnection($params);
}
if (isset($GLOBALS['db_event_subscribers'])) { private static function getConnectionParams() {
$evm = $conn->getEventManager(); if (self::hasRequiredConnectionParams()) {
foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) { return self::getSpecifiedConnectionParams();
$subscriberInstance = new $subscriberClass();
$evm->addEventSubscriber($subscriberInstance);
}
} }
return $conn; return self::getFallbackConnectionParams();
} }
private static function hasRequiredConnectionParams() private static function hasRequiredConnectionParams()
...@@ -108,7 +71,63 @@ class TestUtil ...@@ -108,7 +71,63 @@ class TestUtil
); );
} }
private static function getTmpConnectionParams() private static function getSpecifiedConnectionParams() {
$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 ($platform->supportsCreateDropDatabase()) {
$dbname = $realConn->getDatabase();
$realConn->close();
$tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname);
$tmpConn->close();
} else {
$sm = $realConn->getSchemaManager();
$schema = $sm->createSchema();
$stmts = $schema->toDropSql($realConn->getDatabasePlatform());
foreach ($stmts as $stmt) {
$realConn->exec($stmt);
}
}
return $realDbParams;
}
private static function getFallbackConnectionParams() {
$params = array(
'driver' => 'pdo_sqlite',
'memory' => true
);
if (isset($GLOBALS['db_path'])) {
$params['path'] = $GLOBALS['db_path'];
unlink($GLOBALS['db_path']);
}
return $params;
}
private static function addDbEventSubscribers(Connection $conn) {
if (isset($GLOBALS['db_event_subscribers'])) {
$evm = $conn->getEventManager();
foreach (explode(",", $GLOBALS['db_event_subscribers']) as $subscriberClass) {
$subscriberInstance = new $subscriberClass();
$evm->addEventSubscriber($subscriberInstance);
}
}
}
private static function getParamsForTemporaryConnection()
{ {
$connectionParams = array( $connectionParams = array(
'driver' => $GLOBALS['tmpdb_type'], 'driver' => $GLOBALS['tmpdb_type'],
...@@ -134,7 +153,7 @@ class TestUtil ...@@ -134,7 +153,7 @@ class TestUtil
return $connectionParams; return $connectionParams;
} }
private static function getConnectionParams() private static function getParamsForMainConnection()
{ {
$connectionParams = array( $connectionParams = array(
'driver' => $GLOBALS['db_type'], 'driver' => $GLOBALS['db_type'],
...@@ -157,10 +176,10 @@ class TestUtil ...@@ -157,10 +176,10 @@ class TestUtil
} }
/** /**
* @return \Doctrine\DBAL\Connection * @return Connection
*/ */
public static function getTempConnection() public static function getTempConnection()
{ {
return DriverManager::getConnection(self::getTmpConnectionParams()); return DriverManager::getConnection(self::getParamsForTemporaryConnection());
} }
} }
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