Commit 03bc9350 authored by beberlei's avatar beberlei

[2.0] DDC-156 - Allow to pass custom platforms

parent 845c8555
......@@ -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.");
}
}
\ No newline at end of file
......@@ -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());
}
}
\ No newline at end of file
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