[2.0] DDC-156 - Allow to pass custom platforms
This commit is contained in:
parent
845c85552e
commit
03bc9350dc
@ -22,7 +22,8 @@
|
||||
namespace Doctrine\DBAL;
|
||||
|
||||
use Doctrine\Common\EventManager,
|
||||
Doctrine\Common\DoctrineException;
|
||||
Doctrine\Common\DoctrineException,
|
||||
Doctrine\DBAL\DBALException;
|
||||
|
||||
/**
|
||||
* A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like
|
||||
@ -178,7 +179,13 @@ class Connection
|
||||
|
||||
$this->_config = $config;
|
||||
$this->_eventManager = $eventManager;
|
||||
$this->_platform = $driver->getDatabasePlatform();
|
||||
if (!isset($params['platform'])) {
|
||||
$this->_platform = $driver->getDatabasePlatform();
|
||||
} else if($params['platform'] instanceof \Doctrine\DBAL\Platforms\AbstractPlatform) {
|
||||
$this->_platform = $params['platform'];
|
||||
} else {
|
||||
throw DBALException::invalidPlatformSpecified();
|
||||
}
|
||||
$this->_transactionIsolationLevel = $this->_platform->getDefaultTransactionIsolationLevel();
|
||||
}
|
||||
|
||||
|
@ -8,4 +8,9 @@ class DBALException extends \Exception
|
||||
{
|
||||
return new self("Operation '$method' is not supported.");
|
||||
}
|
||||
|
||||
public static function invalidPlatformSpecified()
|
||||
{
|
||||
return new self("Invalid 'platform' option specified, need to give an instance of \Doctrine\DBAL\Platforms\AbstractPlatform.");
|
||||
}
|
||||
}
|
@ -49,4 +49,16 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver'));
|
||||
}
|
||||
|
||||
public function testCustomPlatform()
|
||||
{
|
||||
$mockPlatform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$options = array(
|
||||
'pdo' => new \PDO('sqlite::memory:'),
|
||||
'platform' => $mockPlatform
|
||||
);
|
||||
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
$this->assertSame($mockPlatform, $conn->getDatabasePlatform());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user