Failed Conditions
Push — master ( 01143c...7811e4 )
by Sergei
21s queued 14s
created

PostgreSQL94PlatformTest::createPlatform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\DBAL\Platforms;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
9
use Doctrine\DBAL\Schema\Table;
10
use Doctrine\DBAL\Types\Types;
11
use function assert;
12
13
class PostgreSQL94PlatformTest extends AbstractPostgreSQLPlatformTestCase
14
{
15
    public function createPlatform() : AbstractPlatform
16
    {
17
        return new PostgreSQL94Platform();
18
    }
19
20
    public function testSupportsPartialIndexes() : void
21
    {
22
        self::assertTrue($this->platform->supportsPartialIndexes());
23
    }
24
25
    public function testGetCreateTableSQLWithColumnCollation() : void
26
    {
27
        $table = new Table('foo');
28
        $table->addColumn('id', 'string');
29
        $table->addOption('comment', 'foo');
30
        self::assertSame(
31
            [
32
                'CREATE TABLE foo (id VARCHAR NOT NULL)',
33
                "COMMENT ON TABLE foo IS 'foo'",
34
            ],
35
            $this->platform->getCreateTableSQL($table),
36
            'Comments are added to table.'
37
        );
38
    }
39
40
    public function testColumnCollationDeclarationSQL() : void
41
    {
42
        self::assertEquals(
43
            'COLLATE "en_US.UTF-8"',
44
            $this->platform->getColumnCollationDeclarationSQL('en_US.UTF-8')
45
        );
46
    }
47
48
    /**
49
     * @group DBAL-553
50
     */
51
    public function testHasNativeJsonType() : void
52
    {
53
        self::assertTrue($this->platform->hasNativeJsonType());
54
    }
55
56
    /**
57
     * @group DBAL-553
58
     */
59
    public function testReturnsJsonTypeDeclarationSQL() : void
60
    {
61
        self::assertSame('JSON', $this->platform->getJsonTypeDeclarationSQL([]));
62
        self::assertSame('JSON', $this->platform->getJsonTypeDeclarationSQL(['jsonb' => false]));
63
        self::assertSame('JSONB', $this->platform->getJsonTypeDeclarationSQL(['jsonb' => true]));
64
    }
65
66
    public function testReturnsSmallIntTypeDeclarationSQL() : void
67
    {
68
        self::assertSame(
69
            'SMALLSERIAL',
70
            $this->platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true])
71
        );
72
73
        self::assertSame(
74
            'SMALLINT',
75
            $this->platform->getSmallIntTypeDeclarationSQL(['autoincrement' => false])
76
        );
77
78
        self::assertSame(
79
            'SMALLINT',
80
            $this->platform->getSmallIntTypeDeclarationSQL([])
81
        );
82
    }
83
84
    /**
85
     * @group DBAL-553
86
     */
87
    public function testInitializesJsonTypeMapping() : void
88
    {
89
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json'));
90
        self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('json'));
91
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('jsonb'));
92
        self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('jsonb'));
93
    }
94
95
    /**
96
     * @group DBAL-1220
97
     */
98
    public function testReturnsCloseActiveDatabaseConnectionsSQL() : void
99
    {
100
        assert($this->platform instanceof PostgreSQL94Platform);
101
102
        self::assertSame(
103
            "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo'",
104
            $this->platform->getCloseActiveDatabaseConnectionsSQL('foo')
105
        );
106
    }
107
}
108