2009-07-15 02:36:09 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\DBAL;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../TestInit.php';
|
|
|
|
|
|
|
|
class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
|
|
|
|
{
|
|
|
|
/**
|
2010-01-24 01:59:48 +03:00
|
|
|
* @expectedException \Doctrine\DBAL\DBALException
|
2009-07-15 02:36:09 +04:00
|
|
|
*/
|
|
|
|
public function testInvalidPdoInstance()
|
|
|
|
{
|
|
|
|
$options = array(
|
|
|
|
'pdo' => 'test'
|
|
|
|
);
|
|
|
|
$test = \Doctrine\DBAL\DriverManager::getConnection($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidPdoInstance()
|
|
|
|
{
|
|
|
|
$options = array(
|
|
|
|
'pdo' => new \PDO('sqlite::memory:')
|
|
|
|
);
|
|
|
|
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
|
|
|
$this->assertEquals('sqlite', $conn->getDatabasePlatform()->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-01-24 01:59:48 +03:00
|
|
|
* @expectedException \Doctrine\DBAL\DBALException
|
2009-07-15 02:36:09 +04:00
|
|
|
*/
|
|
|
|
public function testCheckParams()
|
|
|
|
{
|
|
|
|
$conn = \Doctrine\DBAL\DriverManager::getConnection(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-01-24 01:59:48 +03:00
|
|
|
* @expectedException \Doctrine\DBAL\DBALException
|
2009-07-15 02:36:09 +04:00
|
|
|
*/
|
|
|
|
public function testInvalidDriver()
|
|
|
|
{
|
|
|
|
$conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver'));
|
|
|
|
}
|
2009-12-08 22:41:47 +03:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2010-01-24 02:12:27 +03:00
|
|
|
|
|
|
|
public function testCustomWrapper()
|
|
|
|
{
|
|
|
|
$wrapperMock = $this->getMock('\Doctrine\DBAL\Connection', array(), array(), '', false);
|
|
|
|
$wrapperClass = get_class($wrapperMock);
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
'pdo' => new \PDO('sqlite::memory:'),
|
|
|
|
'wrapperClass' => $wrapperClass
|
|
|
|
);
|
|
|
|
|
|
|
|
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
|
|
|
$this->assertType($wrapperClass, $conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidWrapperClass()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('\Doctrine\DBAL\DBALException');
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
'pdo' => new \PDO('sqlite::memory:'),
|
|
|
|
'wrapperClass' => 'stdClass',
|
|
|
|
);
|
|
|
|
|
|
|
|
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidDriverClass()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('\Doctrine\DBAL\DBALException');
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
'driverClass' => 'stdClass'
|
|
|
|
);
|
|
|
|
|
|
|
|
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidDriverClass()
|
|
|
|
{
|
|
|
|
$options = array(
|
|
|
|
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
|
|
|
|
);
|
|
|
|
|
|
|
|
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
|
|
|
$this->assertType('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver());
|
|
|
|
}
|
2009-07-15 02:36:09 +04:00
|
|
|
}
|