Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / DriverManagerTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL;
4
5 require_once __DIR__ . '/../TestInit.php';
6
7 class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
8 {
9     /**
10      * @expectedException \Doctrine\DBAL\DBALException
11      */
12     public function testInvalidPdoInstance()
13     {
14         $options = array(
15             'pdo' => 'test'
16         );
17         $test = \Doctrine\DBAL\DriverManager::getConnection($options);
18     }
19
20     public function testValidPdoInstance()
21     {
22         $options = array(
23             'pdo' => new \PDO('sqlite::memory:')
24         );
25         $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
26         $this->assertEquals('sqlite', $conn->getDatabasePlatform()->getName());
27     }
28
29     /**
30      * @group DBAL-32
31      */
32     public function testPdoInstanceSetErrorMode()
33     {
34         $pdo = new \PDO('sqlite::memory:');
35         $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
36         $options = array(
37             'pdo' => $pdo
38         );
39
40         $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
41         $this->assertEquals(\PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(\PDO::ATTR_ERRMODE));
42     }
43
44     /**
45      * @expectedException \Doctrine\DBAL\DBALException
46      */
47     public function testCheckParams()
48     {
49         $conn = \Doctrine\DBAL\DriverManager::getConnection(array());
50     }
51
52     /**
53      * @expectedException \Doctrine\DBAL\DBALException
54      */
55     public function testInvalidDriver()
56     {
57         $conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver'));
58     }
59
60     public function testCustomPlatform()
61     {
62         $mockPlatform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
63         $options = array(
64             'pdo' => new \PDO('sqlite::memory:'),
65             'platform' => $mockPlatform
66         );
67
68         $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
69         $this->assertSame($mockPlatform, $conn->getDatabasePlatform());
70     }
71
72     public function testCustomWrapper()
73     {
74         $wrapperClass = 'Doctrine\Tests\Mocks\ConnectionMock';
75
76         $options = array(
77             'pdo' => new \PDO('sqlite::memory:'),
78             'wrapperClass' => $wrapperClass,
79         );
80
81         $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
82         $this->assertInstanceOf($wrapperClass, $conn);
83     }
84
85     public function testInvalidWrapperClass()
86     {
87         $this->setExpectedException('\Doctrine\DBAL\DBALException');
88
89         $options = array(
90             'pdo' => new \PDO('sqlite::memory:'),
91             'wrapperClass' => 'stdClass',
92         );
93
94         $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
95     }
96
97     public function testInvalidDriverClass()
98     {
99         $this->setExpectedException('\Doctrine\DBAL\DBALException');
100
101         $options = array(
102             'driverClass' => 'stdClass'
103         );
104
105         $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
106     }
107
108     public function testValidDriverClass()
109     {
110         $options = array(
111             'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
112         );
113
114         $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
115         $this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver());
116     }
117 }