AbstractDriverTest.php 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?php

namespace Doctrine\Tests\DBAL\Functional\Driver;

use Doctrine\DBAL\Connection;
use Doctrine\Tests\DbalFunctionalTestCase;

abstract class AbstractDriverTest extends DbalFunctionalTestCase
{
    /**
     * The driver instance under test.
     *
     * @var \Doctrine\DBAL\Driver
     */
15
    protected $driver;
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

    protected function setUp()
    {
        parent::setUp();

        $this->driver = $this->createDriver();
    }

    /**
     * @group DBAL-1215
     */
    public function testConnectsWithoutDatabaseNameParameter()
    {
        $params = $this->_conn->getParams();
        unset($params['dbname']);

32 33
        $user = $params['user'] ?? null;
        $password = $params['password'] ?? null;
34 35 36

        $connection = $this->driver->connect($params, $user, $password);

37
        self::assertInstanceOf('Doctrine\DBAL\Driver\Connection', $connection);
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    }

    /**
     * @group DBAL-1215
     */
    public function testReturnsDatabaseNameWithoutDatabaseNameParameter()
    {
        $params = $this->_conn->getParams();
        unset($params['dbname']);

        $connection = new Connection(
            $params,
            $this->_conn->getDriver(),
            $this->_conn->getConfiguration(),
            $this->_conn->getEventManager()
        );

55
        self::assertSame(
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
            $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter(),
            $this->driver->getDatabase($connection)
        );
    }

    /**
     * @return \Doctrine\DBAL\Driver
     */
    abstract protected function createDriver();

    /**
     * @return string|null
     */
    protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter()
    {
        return null;
    }
}