3 namespace Doctrine\Tests\DBAL;
5 require_once __DIR__ . '/../TestInit.php';
7 class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
10 * @expectedException \Doctrine\DBAL\DBALException
12 public function testInvalidPdoInstance()
17 $test = \Doctrine\DBAL\DriverManager::getConnection($options);
20 public function testValidPdoInstance()
23 'pdo' => new \PDO('sqlite::memory:')
25 $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
26 $this->assertEquals('sqlite', $conn->getDatabasePlatform()->getName());
32 public function testPdoInstanceSetErrorMode()
34 $pdo = new \PDO('sqlite::memory:');
35 $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
40 $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
41 $this->assertEquals(\PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(\PDO::ATTR_ERRMODE));
45 * @expectedException \Doctrine\DBAL\DBALException
47 public function testCheckParams()
49 $conn = \Doctrine\DBAL\DriverManager::getConnection(array());
53 * @expectedException \Doctrine\DBAL\DBALException
55 public function testInvalidDriver()
57 $conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver'));
60 public function testCustomPlatform()
62 $mockPlatform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
64 'pdo' => new \PDO('sqlite::memory:'),
65 'platform' => $mockPlatform
68 $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
69 $this->assertSame($mockPlatform, $conn->getDatabasePlatform());
72 public function testCustomWrapper()
74 $wrapperClass = 'Doctrine\Tests\Mocks\ConnectionMock';
77 'pdo' => new \PDO('sqlite::memory:'),
78 'wrapperClass' => $wrapperClass,
81 $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
82 $this->assertInstanceOf($wrapperClass, $conn);
85 public function testInvalidWrapperClass()
87 $this->setExpectedException('\Doctrine\DBAL\DBALException');
90 'pdo' => new \PDO('sqlite::memory:'),
91 'wrapperClass' => 'stdClass',
94 $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
97 public function testInvalidDriverClass()
99 $this->setExpectedException('\Doctrine\DBAL\DBALException');
102 'driverClass' => 'stdClass'
105 $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
108 public function testValidDriverClass()
111 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
114 $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
115 $this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver());