AbstractPostgreSQLDriverTest.php 3.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php

namespace Doctrine\Tests\DBAL\Driver;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;

class AbstractPostgreSQLDriverTest extends AbstractDriverTest
{
    public function testReturnsDatabaseName()
    {
        parent::testReturnsDatabaseName();

        $database = 'bloo';
        $params   = array(
            'user'     => 'foo',
            'password' => 'bar',
        );

21
        $statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock');
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

        $statement->expects($this->once())
            ->method('fetchColumn')
            ->will($this->returnValue($database));

        $connection = $this->getConnectionMock();

        $connection->expects($this->once())
            ->method('getParams')
            ->will($this->returnValue($params));

        $connection->expects($this->once())
            ->method('query')
            ->will($this->returnValue($statement));

        $this->assertSame($database, $this->driver->getDatabase($connection));
    }

    protected function createDriver()
    {
        return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractPostgreSQLDriver');
    }

    protected function createPlatform()
    {
        return new PostgreSqlPlatform();
    }

    protected function createSchemaManager(Connection $connection)
    {
        return new PostgreSqlSchemaManager($connection);
    }

    protected function getDatabasePlatformsForVersions()
    {
        return array(
58 59 60 61 62
            array('9.0.9', 'Doctrine\DBAL\Platforms\PostgreSqlPlatform'),
            array('9.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'),
            array('9.1.0', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'),
            array('9.1.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'),
            array('9.1.9', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'),
63 64 65
            array('9.2', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'),
            array('9.2.0', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'),
            array('9.2.1', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'),
66 67 68 69 70
            array('9.3.6', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'),
            array('9.4', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'),
            array('9.4.0', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'),
            array('9.4.1', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'),
            array('10', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'),
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 103
        );
    }

    protected function getExceptionConversionData()
    {
        return array(
            self::EXCEPTION_CONNECTION => array(
                array(null, '7', 'SQLSTATE[08006]'),
            ),
            self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array(
                array(null, '23503', null),
            ),
            self::EXCEPTION_INVALID_FIELD_NAME => array(
                array(null, '42703', null),
            ),
            self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array(
                array(null, '42702', null),
            ),
            self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array(
                array(null, '23502', null),
            ),
            self::EXCEPTION_SYNTAX_ERROR => array(
                array(null, '42601', null),
            ),
            self::EXCEPTION_TABLE_EXISTS => array(
                array(null, '42P07', null),
            ),
            self::EXCEPTION_TABLE_NOT_FOUND => array(
                array(null, '42P01', null),
            ),
            self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array(
                array(null, '23505', null),
            ),
104 105 106 107
            self::EXCEPTION_DEADLOCK => array(
                array(null, '40001', null),
                array(null, '40P01', null),
            ),
108 109 110
        );
    }
}