X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Fdbal%2Ftests%2FDoctrine%2FTests%2FDBAL%2FConnectionTest.php;fp=vendor%2Fdoctrine%2Fdbal%2Ftests%2FDoctrine%2FTests%2FDBAL%2FConnectionTest.php;h=48fbb69fcd054046e324ce831d6e231018eec80f;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fapplication_blanche.git diff --git a/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/ConnectionTest.php new file mode 100644 index 0000000..48fbb69 --- /dev/null +++ b/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -0,0 +1,177 @@ + 'pdo_mysql', + 'host' => 'localhost', + 'user' => 'root', + 'password' => 'password', + 'port' => '1234' + ); + $this->_conn = \Doctrine\DBAL\DriverManager::getConnection($params); + } + + public function testIsConnected() + { + $this->assertFalse($this->_conn->isConnected()); + } + + public function testNoTransactionActiveByDefault() + { + $this->assertFalse($this->_conn->isTransactionActive()); + } + + public function testCommitWithNoActiveTransaction_ThrowsException() + { + $this->setExpectedException('Doctrine\DBAL\ConnectionException'); + $this->_conn->commit(); + } + + public function testRollbackWithNoActiveTransaction_ThrowsException() + { + $this->setExpectedException('Doctrine\DBAL\ConnectionException'); + $this->_conn->rollback(); + } + + public function testSetRollbackOnlyNoActiveTransaction_ThrowsException() + { + $this->setExpectedException('Doctrine\DBAL\ConnectionException'); + $this->_conn->setRollbackOnly(); + } + + public function testIsRollbackOnlyNoActiveTransaction_ThrowsException() + { + $this->setExpectedException('Doctrine\DBAL\ConnectionException'); + $this->_conn->isRollbackOnly(); + } + + public function testGetConfiguration() + { + $config = $this->_conn->getConfiguration(); + + $this->assertInstanceOf('Doctrine\DBAL\Configuration', $config); + } + + public function testGetHost() + { + $this->assertEquals('localhost', $this->_conn->getHost()); + } + + public function testGetPort() + { + $this->assertEquals('1234', $this->_conn->getPort()); + } + + public function testGetUsername() + { + $this->assertEquals('root', $this->_conn->getUsername()); + } + + public function testGetPassword() + { + $this->assertEquals('password', $this->_conn->getPassword()); + } + + public function testGetDriver() + { + $this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $this->_conn->getDriver()); + } + + public function testGetEventManager() + { + $this->assertInstanceOf('Doctrine\Common\EventManager', $this->_conn->getEventManager()); + } + + public function testConnectDispatchEvent() + { + $listenerMock = $this->getMock('ConnectDispatchEventListener', array('postConnect')); + $listenerMock->expects($this->once())->method('postConnect'); + + $eventManager = new EventManager(); + $eventManager->addEventListener(array(Events::postConnect), $listenerMock); + + $driverMock = $this->getMock('Doctrine\DBAL\Driver'); + $driverMock->expects(($this->at(0))) + ->method('connect'); + $platform = new Mocks\MockPlatform(); + + $conn = new Connection(array('platform' => $platform), $driverMock, new Configuration(), $eventManager); + $conn->connect(); + } + + public function testEventManagerPassedToPlatform() + { + $this->assertInstanceOf('Doctrine\Common\EventManager', $this->_conn->getDatabasePlatform()->getEventManager()); + $this->assertSame($this->_conn->getEventManager(), $this->_conn->getDatabasePlatform()->getEventManager()); + } + + /** + * @expectedException Doctrine\DBAL\DBALException + * @dataProvider getQueryMethods + */ + public function testDriverExceptionIsWrapped($method) + { + $this->setExpectedException('Doctrine\DBAL\DBALException', "An exception occurred while executing 'MUUHAAAAHAAAA': + +SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); + + $con = \Doctrine\DBAL\DriverManager::getConnection(array( + 'driver' => 'pdo_sqlite', + 'memory' => true, + )); + + $con->$method('MUUHAAAAHAAAA'); + } + + public function getQueryMethods() + { + return array( + array('exec'), + array('query'), + array('executeQuery'), + array('executeUpdate'), + array('prepare'), + ); + } + + /** + * Pretty dumb test, however we want to check that the EchoSQLLogger correctly implements the interface. + * + * @group DBAL-11 + */ + public function testEchoSQLLogger() + { + $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); + $this->_conn->getConfiguration()->setSQLLogger($logger); + $this->assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); + } + + /** + * Pretty dumb test, however we want to check that the DebugStack correctly implements the interface. + * + * @group DBAL-11 + */ + public function testDebugSQLStack() + { + $logger = new \Doctrine\DBAL\Logging\DebugStack(); + $this->_conn->getConfiguration()->setSQLLogger($logger); + $this->assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); + } +} \ No newline at end of file