SQLAnywhere16PlatformTest.php 2.28 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\Tests\DBAL\Platforms;

5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6 7 8 9 10
use Doctrine\DBAL\Platforms\SQLAnywhere16Platform;
use Doctrine\DBAL\Schema\Index;

class SQLAnywhere16PlatformTest extends SQLAnywhere12PlatformTest
{
11
    public function createPlatform() : AbstractPlatform
12
    {
Sergei Morozov's avatar
Sergei Morozov committed
13
        return new SQLAnywhere16Platform();
14 15
    }

16
    public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() : void
17
    {
18
        self::assertEquals(
19
            'CREATE UNIQUE INDEX fooindex ON footable (a, b) WITH NULLS DISTINCT',
Sergei Morozov's avatar
Sergei Morozov committed
20
            $this->platform->getCreateIndexSQL(
21 22
                new Index(
                    'fooindex',
Sergei Morozov's avatar
Sergei Morozov committed
23
                    ['a', 'b'],
24 25
                    true,
                    false,
Sergei Morozov's avatar
Sergei Morozov committed
26
                    ['with_nulls_distinct']
27 28 29 30 31 32
                ),
                'footable'
            )
        );

        // WITH NULLS DISTINCT clause not available on primary indexes.
33
        self::assertEquals(
34
            'ALTER TABLE footable ADD PRIMARY KEY (a, b)',
Sergei Morozov's avatar
Sergei Morozov committed
35
            $this->platform->getCreateIndexSQL(
36 37
                new Index(
                    'fooindex',
Sergei Morozov's avatar
Sergei Morozov committed
38
                    ['a', 'b'],
39 40
                    false,
                    true,
Sergei Morozov's avatar
Sergei Morozov committed
41
                    ['with_nulls_distinct']
42 43 44 45 46 47
                ),
                'footable'
            )
        );

        // WITH NULLS DISTINCT clause not available on non-unique indexes.
48
        self::assertEquals(
49
            'CREATE INDEX fooindex ON footable (a, b)',
Sergei Morozov's avatar
Sergei Morozov committed
50
            $this->platform->getCreateIndexSQL(
51 52
                new Index(
                    'fooindex',
Sergei Morozov's avatar
Sergei Morozov committed
53
                    ['a', 'b'],
54 55
                    false,
                    false,
Sergei Morozov's avatar
Sergei Morozov committed
56
                    ['with_nulls_distinct']
57 58 59 60 61 62 63 64
                ),
                'footable'
            )
        );

        parent::testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL();
    }

65
    public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions() : void
66
    {
Luís Cobucci's avatar
Luís Cobucci committed
67
        $this->expectException('UnexpectedValueException');
68

Sergei Morozov's avatar
Sergei Morozov committed
69
        $this->platform->getCreateIndexSQL(
70 71
            new Index(
                'fooindex',
Sergei Morozov's avatar
Sergei Morozov committed
72
                ['a', 'b'],
73 74
                false,
                false,
Sergei Morozov's avatar
Sergei Morozov committed
75
                ['with_nulls_distinct', 'with_nulls_not_distinct']
76 77 78 79 80
            ),
            'footable'
        );
    }
}