Commit 7d746844 authored by beberlei's avatar beberlei

DBAL-32 - Reconfigure any passed PDO instance to throw exceptions

parent 125f3b17
......@@ -109,6 +109,7 @@ final class DriverManager
if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) {
throw DBALException::invalidPdoInstance();
} else if (isset($params['pdo'])) {
$params['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME);
} else {
self::_checkParams($params);
......
......@@ -26,6 +26,21 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
$this->assertEquals('sqlite', $conn->getDatabasePlatform()->getName());
}
/**
* @group DBAL-32
*/
public function testPdoInstanceSetErrorMode()
{
$pdo = new \PDO('sqlite::memory:');
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
$options = array(
'pdo' => $pdo
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
$this->assertEquals(\PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(\PDO::ATTR_ERRMODE));
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
......
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