DriverManagerTest.php 2.83 KB
Newer Older
jwage's avatar
jwage committed
1 2 3 4 5 6 7 8 9
<?php

namespace Doctrine\Tests\DBAL;

require_once __DIR__ . '/../TestInit.php';
 
class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
{
    /**
10
     * @expectedException \Doctrine\DBAL\DBALException
jwage's avatar
jwage committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
     */
    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());
    }

    /**
30
     * @expectedException \Doctrine\DBAL\DBALException
jwage's avatar
jwage committed
31 32 33 34 35 36 37
     */
    public function testCheckParams()
    {
        $conn = \Doctrine\DBAL\DriverManager::getConnection(array());
    }

    /**
38
     * @expectedException \Doctrine\DBAL\DBALException
jwage's avatar
jwage committed
39 40 41 42 43
     */
    public function testInvalidDriver()
    {
        $conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver'));
    }
44 45 46 47 48 49 50 51 52 53 54 55

    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());
    }
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

    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());
    }
jwage's avatar
jwage committed
103
}