AbstractPostgreSQLDriverTest.php 3.85 KB
Newer Older
1 2 3 4 5
<?php

namespace Doctrine\Tests\DBAL\Driver;

use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Driver;
Sergei Morozov's avatar
Sergei Morozov committed
7
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
8
use Doctrine\DBAL\Driver\ResultStatement;
9
use Doctrine\DBAL\Platforms\AbstractPlatform;
10
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
Sergei Morozov's avatar
Sergei Morozov committed
11 12 13
use Doctrine\DBAL\Platforms\PostgreSQL91Platform;
use Doctrine\DBAL\Platforms\PostgreSQL92Platform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
14
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
15
use Doctrine\DBAL\Schema\AbstractSchemaManager;
16 17 18 19
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;

class AbstractPostgreSQLDriverTest extends AbstractDriverTest
{
20
    public function testReturnsDatabaseName(): void
21 22 23 24
    {
        parent::testReturnsDatabaseName();

        $database = 'bloo';
Sergei Morozov's avatar
Sergei Morozov committed
25
        $params   = [
26 27
            'user'     => 'foo',
            'password' => 'bar',
Sergei Morozov's avatar
Sergei Morozov committed
28
        ];
29

30
        $statement = $this->createMock(ResultStatement::class);
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

        $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));

46
        self::assertSame($database, $this->driver->getDatabase($connection));
47 48
    }

49
    protected function createDriver(): Driver
50
    {
Sergei Morozov's avatar
Sergei Morozov committed
51
        return $this->getMockForAbstractClass(AbstractPostgreSQLDriver::class);
52 53
    }

54
    protected function createPlatform(): AbstractPlatform
55 56 57 58
    {
        return new PostgreSqlPlatform();
    }

59
    protected function createSchemaManager(Connection $connection): AbstractSchemaManager
60 61 62 63
    {
        return new PostgreSqlSchemaManager($connection);
    }

64 65 66
    /**
     * {@inheritDoc}
     */
67
    protected function getDatabasePlatformsForVersions(): array
68
    {
Sergei Morozov's avatar
Sergei Morozov committed
69
        return [
Sergei Morozov's avatar
Sergei Morozov committed
70 71 72 73 74 75 76 77 78 79 80 81
            ['9.0.9', PostgreSqlPlatform::class],
            ['9.1', PostgreSQL91Platform::class],
            ['9.1.0', PostgreSQL91Platform::class],
            ['9.1.1', PostgreSQL91Platform::class],
            ['9.1.9', PostgreSQL91Platform::class],
            ['9.2', PostgreSQL92Platform::class],
            ['9.2.0', PostgreSQL92Platform::class],
            ['9.2.1', PostgreSQL92Platform::class],
            ['9.3.6', PostgreSQL92Platform::class],
            ['9.4', PostgreSQL94Platform::class],
            ['9.4.0', PostgreSQL94Platform::class],
            ['9.4.1', PostgreSQL94Platform::class],
Sergei Morozov's avatar
Sergei Morozov committed
82 83
            ['10', PostgreSQL100Platform::class],
        ];
84 85
    }

86 87 88
    /**
     * {@inheritDoc}
     */
89
    protected static function getExceptionConversionData(): array
90
    {
Sergei Morozov's avatar
Sergei Morozov committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
        return [
            self::EXCEPTION_CONNECTION => [
                [null, '7', 'SQLSTATE[08006]'],
            ],
            self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [
                [null, '23503', null],
            ],
            self::EXCEPTION_INVALID_FIELD_NAME => [
                [null, '42703', null],
            ],
            self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [
                [null, '42702', null],
            ],
            self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [
                [null, '23502', null],
            ],
            self::EXCEPTION_SYNTAX_ERROR => [
                [null, '42601', null],
            ],
            self::EXCEPTION_TABLE_EXISTS => [
                [null, '42P07', null],
            ],
            self::EXCEPTION_TABLE_NOT_FOUND => [
                [null, '42P01', null],
            ],
            self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [
                [null, '23505', null],
            ],
            self::EXCEPTION_DEADLOCK => [
                [null, '40001', null],
                [null, '40P01', null],
            ],
        ];
124 125
    }
}