SQLAnywhere12PlatformTest.php 4.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php

namespace Doctrine\Tests\DBAL\Platforms;

use Doctrine\DBAL\Platforms\SQLAnywhere12Platform;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Sequence;

class SQLAnywhere12PlatformTest extends SQLAnywhere11PlatformTest
{
    /**
     * @var \Doctrine\DBAL\Platforms\SQLAnywhere12Platform
     */
    protected $_platform;

    public function createPlatform()
    {
        return new SQLAnywhere12Platform;
    }

    public function testDoesNotSupportSequences()
    {
        $this->markTestSkipped('This version of the platform now supports sequences.');
    }

    public function testSupportsSequences()
    {
28
        self::assertTrue($this->_platform->supportsSequences());
29 30 31 32 33
    }

    public function testGeneratesSequenceSqlCommands()
    {
        $sequence = new Sequence('myseq', 20, 1);
34
        self::assertEquals(
35 36 37
            'CREATE SEQUENCE myseq INCREMENT BY 20 START WITH 1 MINVALUE 1',
            $this->_platform->getCreateSequenceSQL($sequence)
        );
38
        self::assertEquals(
39 40 41
            'ALTER SEQUENCE myseq INCREMENT BY 20',
            $this->_platform->getAlterSequenceSQL($sequence)
        );
42
        self::assertEquals(
43 44 45
            'DROP SEQUENCE myseq',
            $this->_platform->getDropSequenceSQL('myseq')
        );
46
        self::assertEquals(
47 48 49
            'DROP SEQUENCE myseq',
            $this->_platform->getDropSequenceSQL($sequence)
        );
50
        self::assertEquals(
51 52 53
            "SELECT myseq.NEXTVAL",
            $this->_platform->getSequenceNextValSQL('myseq')
        );
54
        self::assertEquals(
55 56 57 58 59 60 61
            'SELECT sequence_name, increment_by, start_with, min_value FROM SYS.SYSSEQUENCE',
            $this->_platform->getListSequencesSQL(null)
        );
    }

    public function testGeneratesDateTimeTzColumnTypeDeclarationSQL()
    {
62
        self::assertEquals(
63 64 65 66 67 68 69 70 71 72 73 74
            'TIMESTAMP WITH TIME ZONE',
            $this->_platform->getDateTimeTzTypeDeclarationSQL(array(
                'length' => 10,
                'fixed' => true,
                'unsigned' => true,
                'autoincrement' => true
            ))
        );
    }

    public function testHasCorrectDateTimeTzFormatString()
    {
75
        self::assertEquals('Y-m-d H:i:s.uP', $this->_platform->getDateTimeTzFormatString());
76 77 78 79
    }

    public function testInitializesDateTimeTzTypeMapping()
    {
80 81
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('timestamp with time zone'));
        self::assertEquals('datetime', $this->_platform->getDoctrineTypeMapping('timestamp with time zone'));
82 83 84 85
    }

    public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL()
    {
86
        self::assertEquals(
87 88 89 90 91 92 93 94 95 96 97 98
            'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) WITH NULLS NOT DISTINCT FOR OLAP WORKLOAD',
            $this->_platform->getCreateIndexSQL(
                new Index(
                    'fooindex',
                    array('a', 'b'),
                    true,
                    false,
                    array('virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload')
                ),
                'footable'
            )
        );
99
        self::assertEquals(
100 101 102 103 104 105 106 107 108 109 110 111
            'CREATE VIRTUAL CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD',
            $this->_platform->getCreateIndexSQL(
                new Index(
                    'fooindex',
                    array('a', 'b'),
                    false,
                    false,
                    array('virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload')
                ),
                'footable'
            )
        );
112 113

        // WITH NULLS NOT DISTINCT clause not available on primary indexes.
114
        self::assertEquals(
115 116 117 118 119 120 121 122 123 124 125 126 127 128
            'ALTER TABLE footable ADD PRIMARY KEY (a, b)',
            $this->_platform->getCreateIndexSQL(
                new Index(
                    'fooindex',
                    array('a', 'b'),
                    false,
                    true,
                    array('with_nulls_not_distinct')
                ),
                'footable'
            )
        );

        // WITH NULLS NOT DISTINCT clause not available on non-unique indexes.
129
        self::assertEquals(
130 131 132 133 134 135 136 137 138 139 140 141
            'CREATE INDEX fooindex ON footable (a, b)',
            $this->_platform->getCreateIndexSQL(
                new Index(
                    'fooindex',
                    array('a', 'b'),
                    false,
                    false,
                    array('with_nulls_not_distinct')
                ),
                'footable'
            )
        );
142 143
    }
}