Failed Conditions
Push — master ( 656579...2742cd )
by Marco
11:55
created

SQLAnywherePlatformTest   F

Complexity

Total Complexity 102

Size/Duplication

Total Lines 1054
Duplicated Lines 20.21 %

Importance

Changes 0
Metric Value
wmc 102
dl 213
loc 1054
rs 0.9221
c 0
b 0
f 0

101 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeneratesPrimaryKeyDeclarationSQL() 13 13 1
A testSupportsForeignKeyOnUpdate() 0 3 1
A testQuotesTableNameInListTableIndexesSQL() 0 3 1
A supportsInlineIndexDeclaration() 0 3 1
A testReturnsBinaryTypeDeclarationSQL() 11 11 1
A testReturnsGuidTypeDeclarationSQL() 0 3 1
A testGeneratesCreateTableSQLWithCommonIndexes() 16 16 1
B testGeneratesColumnTypesDeclarationSQL() 0 34 1
A getCommentOnColumnSQL() 0 6 1
A getQuotedAlterTableRenameIndexSQL() 0 5 1
A getReturnsForeignKeyReferentialActionSQL() 9 9 1
A testDoesNotSupportRegexp() 0 5 1
A testGeneratesDropIndexSQL() 0 9 1
A testDoesNotPreferSequences() 0 3 1
A testModifiesLimitQuery() 0 5 1
A testGeneratesCreateTableSQLWithForeignKeyConstraints() 23 23 1
A testSupportsReleasePoints() 0 3 1
A createPlatform() 0 3 1
A testQuotesSchemaNameInListTableForeignKeysSQL() 0 7 1
A testHasCorrectDateTimeTzFormatString() 0 6 1
A testPrefersIdentityColumns() 0 3 1
A testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns() 0 4 1
A testDoesNotSupportSequences() 0 3 1
A testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns() 0 5 1
A getQuotedAlterTableChangeColumnLengthSQL() 0 3 1
A getQuotedAlterTableRenameColumnSQL() 0 12 1
A getGenerateIndexSql() 0 3 1
A testGeneratesTableAlterationWithRemovedColumnCommentSql() 18 18 1
A getCreateTableColumnTypeCommentsSQL() 0 5 1
A testSupportsSchemas() 0 3 1
A getQuotedNameInIndexSQL() 0 5 1
A testGeneratesTransactionsCommands() 17 17 1
A testDoesNotSupportIndexDeclarationInCreateAlterTableStatements() 0 5 1
A testModifiesLimitQueryWithSubSelect() 0 5 1
A getGenerateAlterTableSql() 0 5 1
A testQuotesSchemaNameInListTableConstraintsSQL() 0 7 1
A testHasNativeGuidType() 0 3 1
A testSupportsIdentityColumns() 0 3 1
A testModifiesLimitQueryWithOffset() 0 9 1
A testSupportsTransactions() 0 3 1
A getCreateTableColumnCommentsSQL() 0 5 1
A testQuotesSchemaNameInListTableColumnsSQL() 0 7 1
A testQuotesSchemaNameInListTableIndexesSQL() 0 7 1
A getQuotedColumnInPrimaryKeySQL() 0 4 1
A getGenerateUniqueIndexSql() 0 3 1
A testSupportsPrimaryConstraints() 0 3 1
A testHasCorrectPlatformName() 0 3 1
A testSupportsSavePoints() 0 3 1
A testGeneratesCreateUnnamedPrimaryKeySQL() 0 14 1
A testQuotesTableNameInListTableForeignKeysSQL() 0 3 1
A testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() 0 4 1
A getQuotesReservedKeywordInTruncateTableSQL() 0 3 1
A getBinaryMaxLength() 0 3 1
A testGeneratesSQLSnippets() 0 71 1
A getBinaryDefaultLength() 0 3 1
A testInitializesDoctrineTypeMappings() 10 10 1
A testSupportsAlterTable() 0 3 1
A getGenerateTableWithMultiColumnUniqueIndexSql() 0 5 1
A testModifiesLimitQueryWithEmptyOffset() 0 5 1
A testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName() 0 4 1
A testQuotesTableNameInListTableConstraintsSQL() 0 3 1
A testSupportsIndexes() 0 3 1
A getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() 0 4 1
A testGeneratesForeignKeyMatchClausesSQL() 0 6 1
A getGenerateForeignKeySql() 0 3 1
A getAlterTableRenameColumnSQL() 0 4 1
A getQuotedAlterTableRenameIndexInSchemaSQL() 0 5 1
A testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() 0 23 1
A testCannotGenerateDropIndexSQLWithInvalidTableParameter() 0 5 1
A testDoesNotSupportInlineColumnComments() 0 3 1
A testCannotGenerateDropIndexSQLWithInvalidIndexParameter() 0 5 1
A testSupportsGettingAffectedRows() 0 3 1
A testHasCorrectDefaultTransactionIsolationLevel() 0 5 1
A getQuotesTableIdentifiersInAlterTableSQL() 0 10 1
A testHasCorrectMaxIdentifierLength() 0 3 1
A getQuotedColumnInIndexSQL() 0 5 1
A getAlterStringToFixedStringSQL() 0 4 1
A testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() 13 13 1
A getAlterTableRenameIndexSQL() 0 4 1
A getQuotesReservedKeywordInIndexDeclarationSQL() 0 3 1
A getAlterTableRenameIndexInSchemaSQL() 0 4 1
A testGeneratesDDLSnippets() 0 21 1
A testGeneratesCreateTableSQLWithCheckConstraints() 13 13 1
A testAppendsLockHint() 6 6 1
A testCannotEmulateSchemas() 0 3 1
A testFixesSchemaElementNames() 0 19 2
A testCannotGenerateCustomConstraintWithCreateConstraintSQL() 0 5 1
A getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() 0 3 1
A testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() 15 15 1
A testCannotGenerateInvalidForeignKeyMatchClauseSQL() 0 5 1
A getGenerateTableSql() 0 3 1
A testSupportsCommentOnStatement() 0 3 1
A testCannotGenerateCommonIndexWithCreateConstraintSQL() 0 5 1
A testSupportsForeignKeyConstraints() 0 3 1
A testCannotGenerateTransactionCommandWithInvalidIsolationLevel() 0 5 1
A testGeneratesUniqueConstraintDeclarationSQL() 12 12 1
A testSupportsCreateDropDatabase() 0 3 1
A getAlterTableColumnCommentsSQL() 0 7 1
A getLockHints() 10 10 1
A testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns() 0 5 1
A getQuotedColumnInForeignKeySQL() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like SQLAnywherePlatformTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SQLAnywherePlatformTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Doctrine\Tests\DBAL\Platforms;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\LockMode;
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
9
use Doctrine\DBAL\Schema\Column;
10
use Doctrine\DBAL\Schema\ColumnDiff;
11
use Doctrine\DBAL\Schema\Comparator;
12
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
13
use Doctrine\DBAL\Schema\Index;
14
use Doctrine\DBAL\Schema\Table;
15
use Doctrine\DBAL\Schema\TableDiff;
16
use Doctrine\DBAL\Types\Type;
17
18
class SQLAnywherePlatformTest extends AbstractPlatformTestCase
19
{
20
    /**
21
     * @var \Doctrine\DBAL\Platforms\SQLAnywherePlatform
22
     */
23
    protected $_platform;
24
25
    public function createPlatform()
26
    {
27
        return new SQLAnywherePlatform;
28
    }
29
30
    public function getGenerateAlterTableSql()
31
    {
32
        return array(
33
            "ALTER TABLE mytable ADD quota INT DEFAULT NULL, DROP foo, ALTER baz VARCHAR(1) DEFAULT 'def' NOT NULL, ALTER bloo BIT DEFAULT '0' NOT NULL",
34
            'ALTER TABLE mytable RENAME userlist'
35
        );
36
    }
37
38
    public function getGenerateForeignKeySql()
39
    {
40
        return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
41
    }
42
43
    public function getGenerateIndexSql()
44
    {
45
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
46
    }
47
48
    public function getGenerateTableSql()
49
    {
50
        return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY (id))';
51
    }
52
53
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
54
    {
55
        return array(
56
            'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
57
            'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)'
58
        );
59
    }
60
61
    public function getGenerateUniqueIndexSql()
62
    {
63
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
64
    }
65
66
    protected function getQuotedColumnInForeignKeySQL()
67
    {
68
        return array(
69
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar"))',
70
        );
71
    }
72
73
    protected function getQuotedColumnInIndexSQL()
74
    {
75
        return array(
76
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)',
77
            'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")'
78
        );
79
    }
80
81
    protected function getQuotedNameInIndexSQL()
82
    {
83
        return array(
84
            'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
85
            'CREATE INDEX "key" ON test (column1)',
86
        );
87
    }
88
89
    protected function getQuotedColumnInPrimaryKeySQL()
90
    {
91
        return array(
92
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))'
93
        );
94
    }
95
96
    public function getCreateTableColumnCommentsSQL()
97
    {
98
        return array(
99
            "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))",
100
            "COMMENT ON COLUMN test.id IS 'This is a comment'",
101
        );
102
    }
103
104
    public function getAlterTableColumnCommentsSQL()
105
    {
106
        return array(
107
            "ALTER TABLE mytable ADD quota INT NOT NULL",
108
            "COMMENT ON COLUMN mytable.quota IS 'A comment'",
109
            "COMMENT ON COLUMN mytable.foo IS NULL",
110
            "COMMENT ON COLUMN mytable.baz IS 'B comment'",
111
        );
112
    }
113
114
    public function getCreateTableColumnTypeCommentsSQL()
115
    {
116
        return array(
117
            "CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))",
118
            "COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
119
        );
120
    }
121
122
    public function testHasCorrectPlatformName()
123
    {
124
        self::assertEquals('sqlanywhere', $this->_platform->getName());
125
    }
126
127 View Code Duplication
    public function testGeneratesCreateTableSQLWithCommonIndexes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129
        $table = new Table('test');
130
        $table->addColumn('id', 'integer');
131
        $table->addColumn('name', 'string', array('length' => 50));
132
        $table->setPrimaryKey(array('id'));
133
        $table->addIndex(array('name'));
134
        $table->addIndex(array('id', 'name'), 'composite_idx');
135
136
        self::assertEquals(
137
            array(
138
                'CREATE TABLE test (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id))',
139
                'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)',
140
                'CREATE INDEX composite_idx ON test (id, name)'
141
            ),
142
            $this->_platform->getCreateTableSQL($table)
143
        );
144
    }
145
146 View Code Duplication
    public function testGeneratesCreateTableSQLWithForeignKeyConstraints()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
147
    {
148
        $table = new Table('test');
149
        $table->addColumn('id', 'integer');
150
        $table->addColumn('fk_1', 'integer');
151
        $table->addColumn('fk_2', 'integer');
152
        $table->setPrimaryKey(array('id'));
153
        $table->addForeignKeyConstraint('foreign_table', array('fk_1', 'fk_2'), array('pk_1', 'pk_2'));
154
        $table->addForeignKeyConstraint(
155
            'foreign_table2',
156
            array('fk_1', 'fk_2'),
157
            array('pk_1', 'pk_2'),
158
            array(),
159
            'named_fk'
160
        );
161
162
        self::assertEquals(
163
            array(
164
                'CREATE TABLE test (id INT NOT NULL, fk_1 INT NOT NULL, fk_2 INT NOT NULL, ' .
165
                'CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2), ' .
166
                'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))'
167
            ),
168
            $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS)
169
        );
170
    }
171
172 View Code Duplication
    public function testGeneratesCreateTableSQLWithCheckConstraints()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
173
    {
174
        $table = new Table('test');
175
        $table->addColumn('id', 'integer');
176
        $table->addColumn('check_max', 'integer', array('platformOptions' => array('max' => 10)));
177
        $table->addColumn('check_min', 'integer', array('platformOptions' => array('min' => 10)));
178
        $table->setPrimaryKey(array('id'));
179
180
        self::assertEquals(
181
            array(
182
                'CREATE TABLE test (id INT NOT NULL, check_max INT NOT NULL, check_min INT NOT NULL, PRIMARY KEY (id), CHECK (check_max <= 10), CHECK (check_min >= 10))'
183
            ),
184
            $this->_platform->getCreateTableSQL($table)
185
        );
186
    }
187
188 View Code Duplication
    public function testGeneratesTableAlterationWithRemovedColumnCommentSql()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
189
    {
190
        $table = new Table('mytable');
191
        $table->addColumn('foo', 'string', array('comment' => 'foo comment'));
192
193
        $tableDiff = new TableDiff('mytable');
194
        $tableDiff->fromTable = $table;
195
        $tableDiff->changedColumns['foo'] = new ColumnDiff(
196
            'foo',
197
            new Column('foo', Type::getType('string')),
198
            array('comment')
199
        );
200
201
        self::assertEquals(
202
            array(
203
                "COMMENT ON COLUMN mytable.foo IS NULL"
204
            ),
205
            $this->_platform->getAlterTableSQL($tableDiff)
206
        );
207
    }
208
209
    /**
210
     * @dataProvider getLockHints
211
     */
212 View Code Duplication
    public function testAppendsLockHint($lockMode, $lockHint)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
213
    {
214
        $fromClause = 'FROM users';
215
        $expectedResult = $fromClause . $lockHint;
216
217
        self::assertSame($expectedResult, $this->_platform->appendLockHint($fromClause, $lockMode));
218
    }
219
220 View Code Duplication
    public function getLockHints()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
221
    {
222
        return array(
223
            array(null, ''),
224
            array(false, ''),
225
            array(true, ''),
226
            array(LockMode::NONE, ' WITH (NOLOCK)'),
227
            array(LockMode::OPTIMISTIC, ''),
228
            array(LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'),
229
            array(LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'),
230
        );
231
    }
232
233
    public function testHasCorrectMaxIdentifierLength()
234
    {
235
        self::assertEquals(128, $this->_platform->getMaxIdentifierLength());
236
    }
237
238
    public function testFixesSchemaElementNames()
239
    {
240
        $maxIdentifierLength = $this->_platform->getMaxIdentifierLength();
241
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
242
        $schemaElementName = '';
243
244
        for ($i = 0; $i < $maxIdentifierLength + 100; $i++) {
245
            $schemaElementName .= $characters[mt_rand(0, strlen($characters) - 1)];
246
        }
247
248
        $fixedSchemaElementName = substr($schemaElementName, 0, $maxIdentifierLength);
249
250
        self::assertEquals(
251
            $fixedSchemaElementName,
252
            $this->_platform->fixSchemaElementName($schemaElementName)
253
        );
254
        self::assertEquals(
255
            $fixedSchemaElementName,
256
            $this->_platform->fixSchemaElementName($fixedSchemaElementName)
257
        );
258
    }
259
260
    public function testGeneratesColumnTypesDeclarationSQL()
261
    {
262
        $fullColumnDef = array(
263
            'length' => 10,
264
            'fixed' => true,
265
            'unsigned' => true,
266
            'autoincrement' => true
267
        );
268
269
        self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array()));
270
        self::assertEquals('UNSIGNED SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array(
271
            'unsigned' => true
272
        )));
273
        self::assertEquals('UNSIGNED SMALLINT IDENTITY', $this->_platform->getSmallIntTypeDeclarationSQL($fullColumnDef));
274
        self::assertEquals('INT', $this->_platform->getIntegerTypeDeclarationSQL(array()));
275
        self::assertEquals('UNSIGNED INT', $this->_platform->getIntegerTypeDeclarationSQL(array(
276
            'unsigned' => true
277
        )));
278
        self::assertEquals('UNSIGNED INT IDENTITY', $this->_platform->getIntegerTypeDeclarationSQL($fullColumnDef));
279
        self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array()));
280
        self::assertEquals('UNSIGNED BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array(
281
            'unsigned' => true
282
        )));
283
        self::assertEquals('UNSIGNED BIGINT IDENTITY', $this->_platform->getBigIntTypeDeclarationSQL($fullColumnDef));
284
        self::assertEquals('LONG BINARY', $this->_platform->getBlobTypeDeclarationSQL($fullColumnDef));
285
        self::assertEquals('BIT', $this->_platform->getBooleanTypeDeclarationSQL($fullColumnDef));
286
        self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL($fullColumnDef));
287
        self::assertEquals('DATE', $this->_platform->getDateTypeDeclarationSQL($fullColumnDef));
288
        self::assertEquals('DATETIME', $this->_platform->getDateTimeTypeDeclarationSQL($fullColumnDef));
289
        self::assertEquals('TIME', $this->_platform->getTimeTypeDeclarationSQL($fullColumnDef));
290
        self::assertEquals('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL($fullColumnDef));
291
292
        self::assertEquals(1, $this->_platform->getVarcharDefaultLength());
293
        self::assertEquals(32767, $this->_platform->getVarcharMaxLength());
294
    }
295
296
    public function testHasNativeGuidType()
297
    {
298
        self::assertTrue($this->_platform->hasNativeGuidType());
299
    }
300
301
    public function testGeneratesDDLSnippets()
302
    {
303
        self::assertEquals("CREATE DATABASE 'foobar'", $this->_platform->getCreateDatabaseSQL('foobar'));
304
        self::assertEquals("CREATE DATABASE 'foobar'", $this->_platform->getCreateDatabaseSQL('"foobar"'));
305
        self::assertEquals("CREATE DATABASE 'create'", $this->_platform->getCreateDatabaseSQL('create'));
306
        self::assertEquals("DROP DATABASE 'foobar'", $this->_platform->getDropDatabaseSQL('foobar'));
307
        self::assertEquals("DROP DATABASE 'foobar'", $this->_platform->getDropDatabaseSQL('"foobar"'));
308
        self::assertEquals("DROP DATABASE 'create'", $this->_platform->getDropDatabaseSQL('create'));
309
        self::assertEquals('CREATE GLOBAL TEMPORARY TABLE', $this->_platform->getCreateTemporaryTableSnippetSQL());
310
        self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->_platform->getStartDatabaseSQL('foobar'));
311
        self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->_platform->getStartDatabaseSQL('"foobar"'));
312
        self::assertEquals("START DATABASE 'create' AUTOSTOP OFF", $this->_platform->getStartDatabaseSQL('create'));
313
        self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->_platform->getStopDatabaseSQL('foobar'));
314
        self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->_platform->getStopDatabaseSQL('"foobar"'));
315
        self::assertEquals('STOP DATABASE "create" UNCONDITIONALLY', $this->_platform->getStopDatabaseSQL('create'));
316
        self::assertEquals('TRUNCATE TABLE foobar', $this->_platform->getTruncateTableSQL('foobar'));
317
        self::assertEquals('TRUNCATE TABLE foobar', $this->_platform->getTruncateTableSQL('foobar'), true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $message of PHPUnit\Framework\Assert::assertEquals(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

317
        self::assertEquals('TRUNCATE TABLE foobar', $this->_platform->getTruncateTableSQL('foobar'), /** @scrutinizer ignore-type */ true);
Loading history...
318
319
        $viewSql = 'SELECT * FROM footable';
320
        self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->_platform->getCreateViewSQL('fooview', $viewSql));
321
        self::assertEquals('DROP VIEW fooview', $this->_platform->getDropViewSQL('fooview'));
322
    }
323
324 View Code Duplication
    public function testGeneratesPrimaryKeyDeclarationSQL()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
325
    {
326
        self::assertEquals(
327
            'CONSTRAINT pk PRIMARY KEY CLUSTERED (a, b)',
328
            $this->_platform->getPrimaryKeyDeclarationSQL(
329
                new Index(null, array('a', 'b'), true, true, array('clustered')),
330
                'pk'
331
            )
332
        );
333
        self::assertEquals(
334
            'PRIMARY KEY (a, b)',
335
            $this->_platform->getPrimaryKeyDeclarationSQL(
336
                new Index(null, array('a', 'b'), true, true)
337
            )
338
        );
339
    }
340
341
    public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns()
342
    {
343
        $this->expectException('\InvalidArgumentException');
344
345
        $this->_platform->getPrimaryKeyDeclarationSQL(new Index('pk', array(), true, true));
346
    }
347
348
    public function testGeneratesCreateUnnamedPrimaryKeySQL()
349
    {
350
        self::assertEquals(
351
            'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)',
352
            $this->_platform->getCreatePrimaryKeySQL(
353
                new Index('pk', array('a', 'b'), true, true, array('clustered')),
354
                'foo'
355
            )
356
        );
357
        self::assertEquals(
358
            'ALTER TABLE foo ADD PRIMARY KEY (a, b)',
359
            $this->_platform->getCreatePrimaryKeySQL(
360
                new Index('any_pk_name', array('a', 'b'), true, true),
361
                new Table('foo')
362
            )
363
        );
364
    }
365
366 View Code Duplication
    public function testGeneratesUniqueConstraintDeclarationSQL()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
367
    {
368
        self::assertEquals(
369
            'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)',
370
            $this->_platform->getUniqueConstraintDeclarationSQL(
371
                'unique_constraint',
372
                new Index(null, array('a', 'b'), true, false, array('clustered'))
373
            )
374
        );
375
        self::assertEquals(
376
            'UNIQUE (a, b)',
377
            $this->_platform->getUniqueConstraintDeclarationSQL(null, new Index(null, array('a', 'b'), true, false))
378
        );
379
    }
380
381
    public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns()
382
    {
383
        $this->expectException('\InvalidArgumentException');
384
385
        $this->_platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', array(), true));
386
    }
387
388
    public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL()
389
    {
390
        self::assertEquals(
391
            'CONSTRAINT fk ' .
392
                'NOT NULL FOREIGN KEY (a, b) ' .
393
                'REFERENCES foreign_table (c, d) ' .
394
                'MATCH UNIQUE SIMPLE ON UPDATE CASCADE ON DELETE SET NULL CHECK ON COMMIT CLUSTERED FOR OLAP WORKLOAD',
395
            $this->_platform->getForeignKeyDeclarationSQL(
396
                new ForeignKeyConstraint(array('a', 'b'), 'foreign_table', array('c', 'd'), 'fk', array(
397
                    'notnull' => true,
398
                    'match' => SQLAnywherePlatform::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE,
399
                    'onUpdate' => 'CASCADE',
400
                    'onDelete' => 'SET NULL',
401
                    'check_on_commit' => true,
402
                    'clustered' => true,
403
                    'for_olap_workload' => true
404
                ))
405
            )
406
        );
407
        self::assertEquals(
408
            'FOREIGN KEY (a, b) REFERENCES foreign_table (c, d)',
409
            $this->_platform->getForeignKeyDeclarationSQL(
410
                new ForeignKeyConstraint(array('a', 'b'), 'foreign_table', array('c', 'd'))
411
            )
412
        );
413
    }
414
415
    public function testGeneratesForeignKeyMatchClausesSQL()
416
    {
417
        self::assertEquals('SIMPLE', $this->_platform->getForeignKeyMatchClauseSQL(1));
418
        self::assertEquals('FULL', $this->_platform->getForeignKeyMatchClauseSQL(2));
419
        self::assertEquals('UNIQUE SIMPLE', $this->_platform->getForeignKeyMatchClauseSQL(129));
420
        self::assertEquals('UNIQUE FULL', $this->_platform->getForeignKeyMatchClauseSQL(130));
421
    }
422
423
    public function testCannotGenerateInvalidForeignKeyMatchClauseSQL()
424
    {
425
        $this->expectException('\InvalidArgumentException');
426
427
        $this->_platform->getForeignKeyMatchCLauseSQL(3);
428
    }
429
430
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns()
431
    {
432
        $this->expectException('\InvalidArgumentException');
433
        $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array(), 'foreign_tbl', array('c', 'd')));
434
    }
435
436
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns()
437
    {
438
        $this->expectException('\InvalidArgumentException');
439
        $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array('a', 'b'), 'foreign_tbl', array()));
440
    }
441
442
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName()
443
    {
444
        $this->expectException('\InvalidArgumentException');
445
        $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array('a', 'b'), '', array('c', 'd')));
446
    }
447
448
    public function testCannotGenerateCommonIndexWithCreateConstraintSQL()
449
    {
450
        $this->expectException('\InvalidArgumentException');
451
452
        $this->_platform->getCreateConstraintSQL(new Index('fooindex', array()), new Table('footable'));
453
    }
454
455
    public function testCannotGenerateCustomConstraintWithCreateConstraintSQL()
456
    {
457
        $this->expectException('\InvalidArgumentException');
458
459
        $this->_platform->getCreateConstraintSQL($this->createMock('\Doctrine\DBAL\Schema\Constraint'), 'footable');
460
    }
461
462 View Code Duplication
    public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
463
    {
464
        self::assertEquals(
465
            'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD',
466
            $this->_platform->getCreateIndexSQL(
467
                new Index(
468
                    'fooindex',
469
                    array('a', 'b'),
470
                    true,
471
                    false,
472
                    array('virtual', 'clustered', 'for_olap_workload')
473
                ),
474
                'footable'
475
            )
476
        );
477
    }
478
479
    public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements()
480
    {
481
        $this->expectException('\Doctrine\DBAL\DBALException');
482
483
        $this->_platform->getIndexDeclarationSQL('index', new Index('index', array()));
484
    }
485
486
    public function testGeneratesDropIndexSQL()
487
    {
488
        $index = new Index('fooindex', array());
489
490
        self::assertEquals('DROP INDEX fooindex', $this->_platform->getDropIndexSQL($index));
491
        self::assertEquals('DROP INDEX footable.fooindex', $this->_platform->getDropIndexSQL($index, 'footable'));
492
        self::assertEquals('DROP INDEX footable.fooindex', $this->_platform->getDropIndexSQL(
493
            $index,
494
            new Table('footable')
495
        ));
496
    }
497
498
    public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter()
499
    {
500
        $this->expectException('\InvalidArgumentException');
501
502
        $this->_platform->getDropIndexSQL(array('index'), 'table');
503
    }
504
505
    public function testCannotGenerateDropIndexSQLWithInvalidTableParameter()
506
    {
507
        $this->expectException('\InvalidArgumentException');
508
509
        $this->_platform->getDropIndexSQL('index', array('table'));
510
    }
511
512
    public function testGeneratesSQLSnippets()
513
    {
514
        self::assertEquals('STRING(column1, "string1", column2, "string2")', $this->_platform->getConcatExpression(
515
            'column1',
516
            '"string1"',
517
            'column2',
518
            '"string2"'
519
        ));
520
        self::assertEquals('CURRENT DATE', $this->_platform->getCurrentDateSQL());
521
        self::assertEquals('CURRENT TIME', $this->_platform->getCurrentTimeSQL());
522
        self::assertEquals('CURRENT TIMESTAMP', $this->_platform->getCurrentTimestampSQL());
523
        self::assertEquals("DATEADD(DAY, 4, '1987/05/02')", $this->_platform->getDateAddDaysExpression("'1987/05/02'", 4));
524
        self::assertEquals("DATEADD(HOUR, 12, '1987/05/02')", $this->_platform->getDateAddHourExpression("'1987/05/02'", 12));
525
        self::assertEquals("DATEADD(MINUTE, 2, '1987/05/02')", $this->_platform->getDateAddMinutesExpression("'1987/05/02'", 2));
526
        self::assertEquals("DATEADD(MONTH, 102, '1987/05/02')", $this->_platform->getDateAddMonthExpression("'1987/05/02'", 102));
527
        self::assertEquals("DATEADD(QUARTER, 5, '1987/05/02')", $this->_platform->getDateAddQuartersExpression("'1987/05/02'", 5));
528
        self::assertEquals("DATEADD(SECOND, 1, '1987/05/02')", $this->_platform->getDateAddSecondsExpression("'1987/05/02'", 1));
529
        self::assertEquals("DATEADD(WEEK, 3, '1987/05/02')", $this->_platform->getDateAddWeeksExpression("'1987/05/02'", 3));
530
        self::assertEquals("DATEADD(YEAR, 10, '1987/05/02')", $this->_platform->getDateAddYearsExpression("'1987/05/02'", 10));
531
        self::assertEquals("DATEDIFF(day, '1987/04/01', '1987/05/02')", $this->_platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'"));
532
        self::assertEquals("DATEADD(DAY, -1 * 4, '1987/05/02')", $this->_platform->getDateSubDaysExpression("'1987/05/02'", 4));
533
        self::assertEquals("DATEADD(HOUR, -1 * 12, '1987/05/02')", $this->_platform->getDateSubHourExpression("'1987/05/02'", 12));
534
        self::assertEquals("DATEADD(MINUTE, -1 * 2, '1987/05/02')", $this->_platform->getDateSubMinutesExpression("'1987/05/02'", 2));
535
        self::assertEquals("DATEADD(MONTH, -1 * 102, '1987/05/02')", $this->_platform->getDateSubMonthExpression("'1987/05/02'", 102));
536
        self::assertEquals("DATEADD(QUARTER, -1 * 5, '1987/05/02')", $this->_platform->getDateSubQuartersExpression("'1987/05/02'", 5));
537
        self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->_platform->getDateSubSecondsExpression("'1987/05/02'", 1));
538
        self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->_platform->getDateSubWeeksExpression("'1987/05/02'", 3));
539
        self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->_platform->getDateSubYearsExpression("'1987/05/02'", 10));
540
        self::assertEquals("Y-m-d H:i:s.u", $this->_platform->getDateTimeFormatString());
541
        self::assertEquals("H:i:s.u", $this->_platform->getTimeFormatString());
542
        self::assertEquals('', $this->_platform->getForUpdateSQL());
543
        self::assertEquals('NEWID()', $this->_platform->getGuidExpression());
544
        self::assertEquals('LOCATE(string_column, substring_column)', $this->_platform->getLocateExpression('string_column', 'substring_column'));
545
        self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->_platform->getLocateExpression('string_column', 'substring_column', 1));
546
        self::assertEquals("HASH(column, 'MD5')", $this->_platform->getMd5Expression('column'));
547
        self::assertEquals('SUBSTRING(column, 5)', $this->_platform->getSubstringExpression('column', 5));
548
        self::assertEquals('SUBSTRING(column, 5, 2)', $this->_platform->getSubstringExpression('column', 5, 2));
549
        self::assertEquals('GLOBAL TEMPORARY', $this->_platform->getTemporaryTableSQL());
550
        self::assertEquals(
551
            'LTRIM(column)',
552
            $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_LEADING)
553
        );
554
        self::assertEquals(
555
            'RTRIM(column)',
556
            $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_TRAILING)
557
        );
558
        self::assertEquals(
559
            'TRIM(column)',
560
            $this->_platform->getTrimExpression('column')
561
        );
562
        self::assertEquals(
563
            'TRIM(column)',
564
            $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_UNSPECIFIED)
565
        );
566
        self::assertEquals(
567
            "SUBSTR(column, PATINDEX('%[^' + c + ']%', column))",
568
            $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_LEADING, 'c')
569
        );
570
        self::assertEquals(
571
            "REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^' + c + ']%', REVERSE(column))))",
572
            $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_TRAILING, 'c')
573
        );
574
        self::assertEquals(
575
            "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " .
576
            "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))",
577
            $this->_platform->getTrimExpression('column', null, 'c')
578
        );
579
        self::assertEquals(
580
            "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " .
581
            "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))",
582
            $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_UNSPECIFIED, 'c')
583
        );
584
    }
585
586
    public function testDoesNotSupportRegexp()
587
    {
588
        $this->expectException('\Doctrine\DBAL\DBALException');
589
590
        $this->_platform->getRegexpExpression();
591
    }
592
593
    public function testHasCorrectDateTimeTzFormatString()
594
    {
595
        // Date time type with timezone is not supported before version 12.
596
        // For versions before we have to ensure that the date time with timezone format
597
        // equals the normal date time format so that it corresponds to the declaration SQL equality (datetimetz -> datetime).
598
        self::assertEquals($this->_platform->getDateTimeFormatString(), $this->_platform->getDateTimeTzFormatString());
599
    }
600
601
    public function testHasCorrectDefaultTransactionIsolationLevel()
602
    {
603
        self::assertEquals(
604
            Connection::TRANSACTION_READ_UNCOMMITTED,
605
            $this->_platform->getDefaultTransactionIsolationLevel()
606
        );
607
    }
608
609 View Code Duplication
    public function testGeneratesTransactionsCommands()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
610
    {
611
        self::assertEquals(
612
            'SET TEMPORARY OPTION isolation_level = 0',
613
            $this->_platform->getSetTransactionIsolationSQL(Connection::TRANSACTION_READ_UNCOMMITTED)
614
        );
615
        self::assertEquals(
616
            'SET TEMPORARY OPTION isolation_level = 1',
617
            $this->_platform->getSetTransactionIsolationSQL(Connection::TRANSACTION_READ_COMMITTED)
618
        );
619
        self::assertEquals(
620
            'SET TEMPORARY OPTION isolation_level = 2',
621
            $this->_platform->getSetTransactionIsolationSQL(Connection::TRANSACTION_REPEATABLE_READ)
622
        );
623
        self::assertEquals(
624
            'SET TEMPORARY OPTION isolation_level = 3',
625
            $this->_platform->getSetTransactionIsolationSQL(Connection::TRANSACTION_SERIALIZABLE)
626
        );
627
    }
628
629
    public function testCannotGenerateTransactionCommandWithInvalidIsolationLevel()
630
    {
631
        $this->expectException('\InvalidArgumentException');
632
633
        $this->_platform->getSetTransactionIsolationSQL('invalid_transaction_isolation_level');
634
    }
635
636
    public function testModifiesLimitQuery()
637
    {
638
        self::assertEquals(
639
            'SELECT TOP 10 * FROM user',
640
            $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0)
641
        );
642
    }
643
644
    public function testModifiesLimitQueryWithEmptyOffset()
645
    {
646
        self::assertEquals(
647
            'SELECT TOP 10 * FROM user',
648
            $this->_platform->modifyLimitQuery('SELECT * FROM user', 10)
649
        );
650
    }
651
652
    public function testModifiesLimitQueryWithOffset()
653
    {
654
        self::assertEquals(
655
            'SELECT TOP 10 START AT 6 * FROM user',
656
            $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 5)
657
        );
658
        self::assertEquals(
659
            'SELECT TOP ALL START AT 6 * FROM user',
660
            $this->_platform->modifyLimitQuery('SELECT * FROM user', 0, 5)
661
        );
662
    }
663
664
    public function testModifiesLimitQueryWithSubSelect()
665
    {
666
        self::assertEquals(
667
            'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl',
668
            $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', 10)
669
        );
670
    }
671
672
    public function testPrefersIdentityColumns()
673
    {
674
        self::assertTrue($this->_platform->prefersIdentityColumns());
675
    }
676
677
    public function testDoesNotPreferSequences()
678
    {
679
        self::assertFalse($this->_platform->prefersSequences());
680
    }
681
682
    public function testSupportsIdentityColumns()
683
    {
684
        self::assertTrue($this->_platform->supportsIdentityColumns());
685
    }
686
687
    public function testSupportsPrimaryConstraints()
688
    {
689
        self::assertTrue($this->_platform->supportsPrimaryConstraints());
690
    }
691
692
    public function testSupportsForeignKeyConstraints()
693
    {
694
        self::assertTrue($this->_platform->supportsForeignKeyConstraints());
695
    }
696
697
    public function testSupportsForeignKeyOnUpdate()
698
    {
699
        self::assertTrue($this->_platform->supportsForeignKeyOnUpdate());
700
    }
701
702
    public function testSupportsAlterTable()
703
    {
704
        self::assertTrue($this->_platform->supportsAlterTable());
705
    }
706
707
    public function testSupportsTransactions()
708
    {
709
        self::assertTrue($this->_platform->supportsTransactions());
710
    }
711
712
    public function testSupportsSchemas()
713
    {
714
        self::assertFalse($this->_platform->supportsSchemas());
715
    }
716
717
    public function testSupportsIndexes()
718
    {
719
        self::assertTrue($this->_platform->supportsIndexes());
720
    }
721
722
    public function testSupportsCommentOnStatement()
723
    {
724
        self::assertTrue($this->_platform->supportsCommentOnStatement());
725
    }
726
727
    public function testSupportsSavePoints()
728
    {
729
        self::assertTrue($this->_platform->supportsSavepoints());
730
    }
731
732
    public function testSupportsReleasePoints()
733
    {
734
        self::assertTrue($this->_platform->supportsReleaseSavepoints());
735
    }
736
737
    public function testSupportsCreateDropDatabase()
738
    {
739
        self::assertTrue($this->_platform->supportsCreateDropDatabase());
740
    }
741
742
    public function testSupportsGettingAffectedRows()
743
    {
744
        self::assertTrue($this->_platform->supportsGettingAffectedRows());
745
    }
746
747
    public function testDoesNotSupportSequences()
748
    {
749
        self::assertFalse($this->_platform->supportsSequences());
750
    }
751
752
    public function testDoesNotSupportInlineColumnComments()
753
    {
754
        self::assertFalse($this->_platform->supportsInlineColumnComments());
755
    }
756
757
    public function testCannotEmulateSchemas()
758
    {
759
        self::assertFalse($this->_platform->canEmulateSchemas());
760
    }
761
762 View Code Duplication
    public function testInitializesDoctrineTypeMappings()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
763
    {
764
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('integer'));
765
        self::assertSame('integer', $this->_platform->getDoctrineTypeMapping('integer'));
766
767
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary'));
768
        self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary'));
769
770
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary'));
771
        self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary'));
772
    }
773
774
    protected function getBinaryDefaultLength()
775
    {
776
        return 1;
777
    }
778
779
    protected function getBinaryMaxLength()
780
    {
781
        return 32767;
782
    }
783
784 View Code Duplication
    public function testReturnsBinaryTypeDeclarationSQL()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
785
    {
786
        self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array()));
787
        self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
788
        self::assertSame('VARBINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 32767)));
789
        self::assertSame('LONG BINARY', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 32768)));
790
791
        self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
792
        self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
793
        self::assertSame('BINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 32767)));
794
        self::assertSame('LONG BINARY', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 32768)));
795
    }
796
797
    /**
798
     * @group DBAL-234
799
     */
800
    protected function getAlterTableRenameIndexSQL()
801
    {
802
        return array(
803
            'ALTER INDEX idx_foo ON mytable RENAME TO idx_bar',
804
        );
805
    }
806
807
    /**
808
     * @group DBAL-234
809
     */
810
    protected function getQuotedAlterTableRenameIndexSQL()
811
    {
812
        return array(
813
            'ALTER INDEX "create" ON "table" RENAME TO "select"',
814
            'ALTER INDEX "foo" ON "table" RENAME TO "bar"',
815
        );
816
    }
817
818
    /**
819
     * {@inheritdoc}
820
     */
821
    protected function getQuotedAlterTableRenameColumnSQL()
822
    {
823
        return array(
824
            'ALTER TABLE mytable RENAME unquoted1 TO unquoted',
825
            'ALTER TABLE mytable RENAME unquoted2 TO "where"',
826
            'ALTER TABLE mytable RENAME unquoted3 TO "foo"',
827
            'ALTER TABLE mytable RENAME "create" TO reserved_keyword',
828
            'ALTER TABLE mytable RENAME "table" TO "from"',
829
            'ALTER TABLE mytable RENAME "select" TO "bar"',
830
            'ALTER TABLE mytable RENAME quoted1 TO quoted',
831
            'ALTER TABLE mytable RENAME quoted2 TO "and"',
832
            'ALTER TABLE mytable RENAME quoted3 TO "baz"',
833
        );
834
    }
835
836
    /**
837
     * {@inheritdoc}
838
     */
839
    protected function getQuotedAlterTableChangeColumnLengthSQL()
840
    {
841
        $this->markTestIncomplete('Not implemented yet');
842
    }
843
844
    /**
845
     * @group DBAL-807
846
     */
847
    protected function getAlterTableRenameIndexInSchemaSQL()
848
    {
849
        return array(
850
            'ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar',
851
        );
852
    }
853
854
    /**
855
     * @group DBAL-807
856
     */
857
    protected function getQuotedAlterTableRenameIndexInSchemaSQL()
858
    {
859
        return array(
860
            'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"',
861
            'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"',
862
        );
863
    }
864
865
    /**
866
     * @group DBAL-423
867
     */
868
    public function testReturnsGuidTypeDeclarationSQL()
869
    {
870
        self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array()));
871
    }
872
873
    /**
874
     * {@inheritdoc}
875
     */
876
    public function getAlterTableRenameColumnSQL()
877
    {
878
        return array(
879
            'ALTER TABLE foo RENAME bar TO baz',
880
        );
881
    }
882
883
    /**
884
     * {@inheritdoc}
885
     */
886
    protected function getQuotesTableIdentifiersInAlterTableSQL()
887
    {
888
        return array(
889
            'ALTER TABLE "foo" DROP FOREIGN KEY fk1',
890
            'ALTER TABLE "foo" DROP FOREIGN KEY fk2',
891
            'ALTER TABLE "foo" RENAME id TO war',
892
            'ALTER TABLE "foo" ADD bloo INT NOT NULL, DROP baz, ALTER bar INT DEFAULT NULL',
893
            'ALTER TABLE "foo" RENAME "table"',
894
            'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
895
            'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
896
        );
897
    }
898
899
    /**
900
     * {@inheritdoc}
901
     */
902
    protected function getCommentOnColumnSQL()
903
    {
904
        return array(
905
            'COMMENT ON COLUMN foo.bar IS \'comment\'',
906
            'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'',
907
            'COMMENT ON COLUMN "select"."from" IS \'comment\'',
908
        );
909
    }
910
911
    /**
912
     * @group DBAL-1004
913
     */
914 View Code Duplication
    public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
915
    {
916
        $table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'))));
917
        $table2 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'), array('comment' => 'baz'))));
918
919
        $comparator = new Comparator();
920
921
        $tableDiff = $comparator->diffTable($table1, $table2);
922
923
        self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
924
        self::assertSame(
925
            array(
926
                'COMMENT ON COLUMN "foo"."bar" IS \'baz\'',
927
            ),
928
            $this->_platform->getAlterTableSQL($tableDiff)
929
        );
930
    }
931
932
    /**
933
     * {@inheritdoc}
934
     */
935 View Code Duplication
    public function getReturnsForeignKeyReferentialActionSQL()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
936
    {
937
        return array(
938
            array('CASCADE', 'CASCADE'),
939
            array('SET NULL', 'SET NULL'),
940
            array('NO ACTION', 'RESTRICT'),
941
            array('RESTRICT', 'RESTRICT'),
942
            array('SET DEFAULT', 'SET DEFAULT'),
943
            array('CaScAdE', 'CASCADE'),
944
        );
945
    }
946
947
    /**
948
     * {@inheritdoc}
949
     */
950
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
951
    {
952
        return 'CONSTRAINT "select" UNIQUE (foo)';
953
    }
954
955
    /**
956
     * {@inheritdoc}
957
     */
958
    protected function getQuotesReservedKeywordInIndexDeclarationSQL()
959
    {
960
        return ''; // not supported by this platform
961
    }
962
963
    /**
964
     * {@inheritdoc}
965
     */
966
    protected function getQuotesReservedKeywordInTruncateTableSQL()
967
    {
968
        return 'TRUNCATE TABLE "select"';
969
    }
970
971
    /**
972
     * {@inheritdoc}
973
     */
974
    protected function supportsInlineIndexDeclaration()
975
    {
976
        return false;
977
    }
978
979
    /**
980
     * {@inheritdoc}
981
     */
982
    protected function getAlterStringToFixedStringSQL()
983
    {
984
        return array(
985
            'ALTER TABLE mytable ALTER name CHAR(2) NOT NULL',
986
        );
987
    }
988
989
    /**
990
     * {@inheritdoc}
991
     */
992
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
993
    {
994
        return array(
995
            'ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed',
996
        );
997
    }
998
999
    /**
1000
     * @group DBAL-2436
1001
     */
1002
    public function testQuotesSchemaNameInListTableColumnsSQL()
1003
    {
1004
        self::assertContains(
1005
            "'Foo''Bar\\'",
1006
            $this->_platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"),
1007
            '',
1008
            true
1009
        );
1010
    }
1011
1012
    /**
1013
     * @group DBAL-2436
1014
     */
1015
    public function testQuotesTableNameInListTableConstraintsSQL()
1016
    {
1017
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
1018
    }
1019
1020
    /**
1021
     * @group DBAL-2436
1022
     */
1023
    public function testQuotesSchemaNameInListTableConstraintsSQL()
1024
    {
1025
        self::assertContains(
1026
            "'Foo''Bar\\'",
1027
            $this->_platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table"),
1028
            '',
1029
            true
1030
        );
1031
    }
1032
1033
    /**
1034
     * @group DBAL-2436
1035
     */
1036
    public function testQuotesTableNameInListTableForeignKeysSQL()
1037
    {
1038
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
1039
    }
1040
1041
    /**
1042
     * @group DBAL-2436
1043
     */
1044
    public function testQuotesSchemaNameInListTableForeignKeysSQL()
1045
    {
1046
        self::assertContains(
1047
            "'Foo''Bar\\'",
1048
            $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"),
1049
            '',
1050
            true
1051
        );
1052
    }
1053
1054
    /**
1055
     * @group DBAL-2436
1056
     */
1057
    public function testQuotesTableNameInListTableIndexesSQL()
1058
    {
1059
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
1060
    }
1061
1062
    /**
1063
     * @group DBAL-2436
1064
     */
1065
    public function testQuotesSchemaNameInListTableIndexesSQL()
1066
    {
1067
        self::assertContains(
1068
            "'Foo''Bar\\'",
1069
            $this->_platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"),
1070
            '',
1071
            true
1072
        );
1073
    }
1074
}
1075