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

DB2PlatformTest   F

Complexity

Total Complexity 59

Size/Duplication

Total Lines 707
Duplicated Lines 20.23 %

Importance

Changes 0
Metric Value
wmc 59
dl 143
loc 707
rs 3.6363
c 0
b 0
f 0

58 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeneratesAlterColumnSQL() 0 15 2
A testGeneratesDDLSnippets() 0 11 1
A getQuotedAlterTableRenameColumnSQL() 13 13 1
A getAlterTableRenameIndexSQL() 0 4 1
A getIsCommentedDoctrineType() 0 7 1
A getQuotesTableIdentifiersInAlterTableSQL() 14 14 1
A getGenerateAlterTableSql() 14 14 1
A testDoesNotSupportCreateDropDatabase() 0 3 1
A getGenerateIndexSql() 0 3 1
A testHasCorrectPlatformName() 0 3 1
A getAlterTableRenameIndexInSchemaSQL() 0 4 1
A supportsCommentOnStatement() 0 3 1
A getQuotesReservedKeywordInIndexDeclarationSQL() 0 3 1
B testInitializesDoctrineTypeMappings() 0 42 1
A getGenerateUniqueIndexSql() 0 3 1
A testDoesNotSupportReleasePoints() 0 3 1
A getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() 0 4 1
A getQuotedAlterTableRenameIndexInSchemaSQL() 0 5 1
A createPlatform() 0 3 1
A getAlterTableRenameColumnSQL() 0 4 1
A getQuotedColumnInForeignKeySQL() 0 7 1
A getQuotedNameInIndexSQL() 0 5 1
A getQuotedColumnInPrimaryKeySQL() 0 4 1
B testGeneratesSQLSnippets() 0 28 1
A testGeneratesCreateTableSQLWithCheckConstraints() 13 13 1
A getGenerateForeignKeySql() 0 3 1
A getQuotedAlterTableChangeColumnLengthSQL() 0 3 1
B testGeneratesColumnTypesDeclarationSQL() 0 36 1
A supportsInlineIndexDeclaration() 0 3 1
A getCreateTableColumnTypeCommentsSQL() 0 5 1
A getCreateTableColumnCommentsSQL() 0 5 1
A getQuotesReservedKeywordInTruncateTableSQL() 0 3 1
A testReturnsBinaryTypeDeclarationSQL() 11 11 1
A getCommentOnColumnSQL() 0 6 1
A getGenerateTableWithMultiColumnUniqueIndexSql() 0 5 1
A testQuotesTableNameInListTableIndexesSQL() 0 3 1
A getGeneratesAlterColumnSQL() 0 57 1
A testQuotesTableNameInListTableForeignKeysSQL() 0 3 1
A testDoesNotSupportSavePoints() 0 3 1
B testModifiesLimitQuery() 24 24 1
A getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() 0 3 1
A getBitOrComparisonExpressionSql() 0 3 1
A testGeneratesCreateUnnamedPrimaryKeySQL() 0 7 1
A testGeneratesCreateTableSQLWithForeignKeyConstraints() 23 23 1
A getAlterTableColumnCommentsSQL() 0 9 1
A getQuotedColumnInIndexSQL() 0 5 1
A testQuotesTableNameInListTableColumnsSQL() 0 3 1
A getGenerateTableSql() 0 3 1
A testSupportsIdentityColumns() 0 3 1
A testReturnsSQLResultCasing() 0 3 1
A getBinaryMaxLength() 0 3 1
A getBitAndComparisonExpressionSql() 0 3 1
A getQuotedAlterTableRenameIndexSQL() 0 5 1
A testGeneratesCreateTableSQLWithCommonIndexes() 16 16 1
A testPrefersIdentityColumns() 0 3 1
A getAlterStringToFixedStringSQL() 0 5 1
A getBinaryDefaultLength() 0 3 1
A testReturnsGuidTypeDeclarationSQL() 0 3 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 DB2PlatformTest 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 DB2PlatformTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Doctrine\Tests\DBAL\Platforms;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Platforms\DB2Platform;
7
use Doctrine\DBAL\Schema\Column;
8
use Doctrine\DBAL\Schema\ColumnDiff;
9
use Doctrine\DBAL\Schema\Index;
10
use Doctrine\DBAL\Schema\Table;
11
use Doctrine\DBAL\Schema\TableDiff;
12
use Doctrine\DBAL\Types\Type;
13
14
class DB2PlatformTest extends AbstractPlatformTestCase
15
{
16
    /**
17
     * @var \Doctrine\DBAL\Platforms\DB2Platform
18
     */
19
    protected $_platform;
20
21
    public function createPlatform()
22
    {
23
        return new DB2Platform();
24
    }
25
26 View Code Duplication
    public function getGenerateAlterTableSql()
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...
27
    {
28
        return array(
29
            "ALTER TABLE mytable ALTER COLUMN baz SET DATA TYPE VARCHAR(255)",
30
            "ALTER TABLE mytable ALTER COLUMN baz SET NOT NULL",
31
            "ALTER TABLE mytable ALTER COLUMN baz SET DEFAULT 'def'",
32
            "ALTER TABLE mytable ALTER COLUMN bloo SET DATA TYPE SMALLINT",
33
            "ALTER TABLE mytable ALTER COLUMN bloo SET NOT NULL",
34
            "ALTER TABLE mytable ALTER COLUMN bloo SET DEFAULT '0'",
35
            "ALTER TABLE mytable " .
36
            "ADD COLUMN quota INTEGER DEFAULT NULL " .
37
            "DROP COLUMN foo",
38
            "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')",
39
            'RENAME TABLE mytable TO userlist',
40
        );
41
    }
42
43
    public function getGenerateForeignKeySql()
44
    {
45
        return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
46
    }
47
48
    public function getGenerateIndexSql()
49
    {
50
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
51
    }
52
53
    public function getGenerateTableSql()
54
    {
55
        return 'CREATE TABLE test (id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
56
    }
57
58
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
59
    {
60
        return array(
61
            'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
62
            'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)'
63
        );
64
    }
65
66
    public function getGenerateUniqueIndexSql()
67
    {
68
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
69
    }
70
71
    protected function getQuotedColumnInForeignKeySQL()
72
    {
73
        return array(
74
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)',
75
            'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar")',
76
            'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar")',
77
            'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar")',
78
        );
79
    }
80
81
    protected function getQuotedColumnInIndexSQL()
82
    {
83
        return array(
84
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)',
85
            'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")'
86
        );
87
    }
88
89
    protected function getQuotedNameInIndexSQL()
90
    {
91
        return array(
92
            'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
93
            'CREATE INDEX "key" ON test (column1)',
94
        );
95
    }
96
97
    protected function getQuotedColumnInPrimaryKeySQL()
98
    {
99
        return array(
100
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))'
101
        );
102
    }
103
104
    protected function getBitAndComparisonExpressionSql($value1, $value2)
105
    {
106
        return 'BITAND(' . $value1 . ', ' . $value2 . ')';
107
    }
108
109
    protected  function getBitOrComparisonExpressionSql($value1, $value2)
110
    {
111
        return 'BITOR(' . $value1 . ', ' . $value2 . ')';
112
    }
113
114
    public function getCreateTableColumnCommentsSQL()
115
    {
116
        return array(
117
            "CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))",
118
            "COMMENT ON COLUMN test.id IS 'This is a comment'",
119
        );
120
    }
121
122
    public function getAlterTableColumnCommentsSQL()
123
    {
124
        return array(
125
            "ALTER TABLE mytable " .
126
            "ADD COLUMN quota INTEGER NOT NULL WITH DEFAULT",
127
            "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')",
128
            "COMMENT ON COLUMN mytable.quota IS 'A comment'",
129
            "COMMENT ON COLUMN mytable.foo IS ''",
130
            "COMMENT ON COLUMN mytable.baz IS 'B comment'",
131
        );
132
    }
133
134
    public function getCreateTableColumnTypeCommentsSQL()
135
    {
136
        return array(
137
            'CREATE TABLE test (id INTEGER NOT NULL, "data" CLOB(1M) NOT NULL, PRIMARY KEY(id))',
138
            'COMMENT ON COLUMN test."data" IS \'(DC2Type:array)\'',
139
        );
140
    }
141
142
    public function testHasCorrectPlatformName()
143
    {
144
        self::assertEquals('db2', $this->_platform->getName());
145
    }
146
147 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...
148
    {
149
        $table = new Table('test');
150
        $table->addColumn('id', 'integer');
151
        $table->addColumn('name', 'string', array('length' => 50));
152
        $table->setPrimaryKey(array('id'));
153
        $table->addIndex(array('name'));
154
        $table->addIndex(array('id', 'name'), 'composite_idx');
155
156
        self::assertEquals(
157
            array(
158
                'CREATE TABLE test (id INTEGER NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id))',
159
                'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)',
160
                'CREATE INDEX composite_idx ON test (id, name)'
161
            ),
162
            $this->_platform->getCreateTableSQL($table)
163
        );
164
    }
165
166 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...
167
    {
168
        $table = new Table('test');
169
        $table->addColumn('id', 'integer');
170
        $table->addColumn('fk_1', 'integer');
171
        $table->addColumn('fk_2', 'integer');
172
        $table->setPrimaryKey(array('id'));
173
        $table->addForeignKeyConstraint('foreign_table', array('fk_1', 'fk_2'), array('pk_1', 'pk_2'));
174
        $table->addForeignKeyConstraint(
175
            'foreign_table2',
176
            array('fk_1', 'fk_2'),
177
            array('pk_1', 'pk_2'),
178
            array(),
179
            'named_fk'
180
        );
181
182
        self::assertEquals(
183
            array(
184
                'CREATE TABLE test (id INTEGER NOT NULL, fk_1 INTEGER NOT NULL, fk_2 INTEGER NOT NULL)',
185
                'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2)',
186
                'ALTER TABLE test ADD CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2)',
187
            ),
188
            $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS)
189
        );
190
    }
191
192 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...
193
    {
194
        $table = new Table('test');
195
        $table->addColumn('id', 'integer');
196
        $table->addColumn('check_max', 'integer', array('platformOptions' => array('max' => 10)));
197
        $table->addColumn('check_min', 'integer', array('platformOptions' => array('min' => 10)));
198
        $table->setPrimaryKey(array('id'));
199
200
        self::assertEquals(
201
            array(
202
                'CREATE TABLE test (id INTEGER NOT NULL, check_max INTEGER NOT NULL, check_min INTEGER NOT NULL, PRIMARY KEY(id), CHECK (check_max <= 10), CHECK (check_min >= 10))'
203
            ),
204
            $this->_platform->getCreateTableSQL($table)
205
        );
206
    }
207
208
    public function testGeneratesColumnTypesDeclarationSQL()
209
    {
210
        $fullColumnDef = array(
211
            'length' => 10,
212
            'fixed' => true,
213
            'unsigned' => true,
214
            'autoincrement' => true
215
        );
216
217
        self::assertEquals('VARCHAR(255)', $this->_platform->getVarcharTypeDeclarationSQL(array()));
218
        self::assertEquals('VARCHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 10)));
219
        self::assertEquals('CHAR(255)', $this->_platform->getVarcharTypeDeclarationSQL(array('fixed' => true)));
220
        self::assertEquals('CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL($fullColumnDef));
221
222
        self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array()));
223
        self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array(
224
            'unsigned' => true
225
        )));
226
        self::assertEquals('SMALLINT GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getSmallIntTypeDeclarationSQL($fullColumnDef));
227
        self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(array()));
228
        self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(array(
229
            'unsigned' => true
230
        )));
231
        self::assertEquals('INTEGER GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getIntegerTypeDeclarationSQL($fullColumnDef));
232
        self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array()));
233
        self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array(
234
            'unsigned' => true
235
        )));
236
        self::assertEquals('BIGINT GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getBigIntTypeDeclarationSQL($fullColumnDef));
237
        self::assertEquals('BLOB(1M)', $this->_platform->getBlobTypeDeclarationSQL($fullColumnDef));
238
        self::assertEquals('SMALLINT', $this->_platform->getBooleanTypeDeclarationSQL($fullColumnDef));
239
        self::assertEquals('CLOB(1M)', $this->_platform->getClobTypeDeclarationSQL($fullColumnDef));
240
        self::assertEquals('DATE', $this->_platform->getDateTypeDeclarationSQL($fullColumnDef));
241
        self::assertEquals('TIMESTAMP(0) WITH DEFAULT', $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true)));
242
        self::assertEquals('TIMESTAMP(0)', $this->_platform->getDateTimeTypeDeclarationSQL($fullColumnDef));
243
        self::assertEquals('TIME', $this->_platform->getTimeTypeDeclarationSQL($fullColumnDef));
244
    }
245
246
    public function testInitializesDoctrineTypeMappings()
247
    {
248
        $this->_platform->initializeDoctrineTypeMappings();
249
250
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('smallint'));
251
        self::assertSame('smallint', $this->_platform->getDoctrineTypeMapping('smallint'));
252
253
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('bigint'));
254
        self::assertSame('bigint', $this->_platform->getDoctrineTypeMapping('bigint'));
255
256
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('integer'));
257
        self::assertSame('integer', $this->_platform->getDoctrineTypeMapping('integer'));
258
259
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('time'));
260
        self::assertSame('time', $this->_platform->getDoctrineTypeMapping('time'));
261
262
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('date'));
263
        self::assertSame('date', $this->_platform->getDoctrineTypeMapping('date'));
264
265
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varchar'));
266
        self::assertSame('string', $this->_platform->getDoctrineTypeMapping('varchar'));
267
268
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('character'));
269
        self::assertSame('string', $this->_platform->getDoctrineTypeMapping('character'));
270
271
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('clob'));
272
        self::assertSame('text', $this->_platform->getDoctrineTypeMapping('clob'));
273
274
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('blob'));
275
        self::assertSame('blob', $this->_platform->getDoctrineTypeMapping('blob'));
276
277
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('decimal'));
278
        self::assertSame('decimal', $this->_platform->getDoctrineTypeMapping('decimal'));
279
280
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('double'));
281
        self::assertSame('float', $this->_platform->getDoctrineTypeMapping('double'));
282
283
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('real'));
284
        self::assertSame('float', $this->_platform->getDoctrineTypeMapping('real'));
285
286
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('timestamp'));
287
        self::assertSame('datetime', $this->_platform->getDoctrineTypeMapping('timestamp'));
288
    }
289
290
    public function getIsCommentedDoctrineType()
291
    {
292
        $data = parent::getIsCommentedDoctrineType();
293
294
        $data[Type::BOOLEAN] = array(Type::getType(Type::BOOLEAN), true);
295
296
        return $data;
297
    }
298
299
    public function testGeneratesDDLSnippets()
300
    {
301
        self::assertEquals("CREATE DATABASE foobar", $this->_platform->getCreateDatabaseSQL('foobar'));
302
        self::assertEquals("DROP DATABASE foobar", $this->_platform->getDropDatabaseSQL('foobar'));
303
        self::assertEquals('DECLARE GLOBAL TEMPORARY TABLE', $this->_platform->getCreateTemporaryTableSnippetSQL());
304
        self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->_platform->getTruncateTableSQL('foobar'));
305
        self::assertEquals('TRUNCATE foobar IMMEDIATE', $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

305
        self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->_platform->getTruncateTableSQL('foobar'), /** @scrutinizer ignore-type */ true);
Loading history...
306
307
        $viewSql = 'SELECT * FROM footable';
308
        self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->_platform->getCreateViewSQL('fooview', $viewSql));
309
        self::assertEquals('DROP VIEW fooview', $this->_platform->getDropViewSQL('fooview'));
310
    }
311
312
    public function testGeneratesCreateUnnamedPrimaryKeySQL()
313
    {
314
        self::assertEquals(
315
            'ALTER TABLE foo ADD PRIMARY KEY (a, b)',
316
            $this->_platform->getCreatePrimaryKeySQL(
317
                new Index('any_pk_name', array('a', 'b'), true, true),
318
                'foo'
319
            )
320
        );
321
    }
322
323
    public function testGeneratesSQLSnippets()
324
    {
325
        self::assertEquals('CURRENT DATE', $this->_platform->getCurrentDateSQL());
326
        self::assertEquals('CURRENT TIME', $this->_platform->getCurrentTimeSQL());
327
        self::assertEquals('CURRENT TIMESTAMP', $this->_platform->getCurrentTimestampSQL());
328
        self::assertEquals("'1987/05/02' + 4 DAY", $this->_platform->getDateAddDaysExpression("'1987/05/02'", 4));
329
        self::assertEquals("'1987/05/02' + 12 HOUR", $this->_platform->getDateAddHourExpression("'1987/05/02'", 12));
330
        self::assertEquals("'1987/05/02' + 2 MINUTE", $this->_platform->getDateAddMinutesExpression("'1987/05/02'", 2));
331
        self::assertEquals("'1987/05/02' + 102 MONTH", $this->_platform->getDateAddMonthExpression("'1987/05/02'", 102));
332
        self::assertEquals("'1987/05/02' + 15 MONTH", $this->_platform->getDateAddQuartersExpression("'1987/05/02'", 5));
333
        self::assertEquals("'1987/05/02' + 1 SECOND", $this->_platform->getDateAddSecondsExpression("'1987/05/02'", 1));
334
        self::assertEquals("'1987/05/02' + 21 DAY", $this->_platform->getDateAddWeeksExpression("'1987/05/02'", 3));
335
        self::assertEquals("'1987/05/02' + 10 YEAR", $this->_platform->getDateAddYearsExpression("'1987/05/02'", 10));
336
        self::assertEquals("DAYS('1987/05/02') - DAYS('1987/04/01')", $this->_platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'"));
337
        self::assertEquals("'1987/05/02' - 4 DAY", $this->_platform->getDateSubDaysExpression("'1987/05/02'", 4));
338
        self::assertEquals("'1987/05/02' - 12 HOUR", $this->_platform->getDateSubHourExpression("'1987/05/02'", 12));
339
        self::assertEquals("'1987/05/02' - 2 MINUTE", $this->_platform->getDateSubMinutesExpression("'1987/05/02'", 2));
340
        self::assertEquals("'1987/05/02' - 102 MONTH", $this->_platform->getDateSubMonthExpression("'1987/05/02'", 102));
341
        self::assertEquals("'1987/05/02' - 15 MONTH", $this->_platform->getDateSubQuartersExpression("'1987/05/02'", 5));
342
        self::assertEquals("'1987/05/02' - 1 SECOND", $this->_platform->getDateSubSecondsExpression("'1987/05/02'", 1));
343
        self::assertEquals("'1987/05/02' - 21 DAY", $this->_platform->getDateSubWeeksExpression("'1987/05/02'", 3));
344
        self::assertEquals("'1987/05/02' - 10 YEAR", $this->_platform->getDateSubYearsExpression("'1987/05/02'", 10));
345
        self::assertEquals(' WITH RR USE AND KEEP UPDATE LOCKS', $this->_platform->getForUpdateSQL());
346
        self::assertEquals('LOCATE(substring_column, string_column)', $this->_platform->getLocateExpression('string_column', 'substring_column'));
347
        self::assertEquals('LOCATE(substring_column, string_column)', $this->_platform->getLocateExpression('string_column', 'substring_column'));
348
        self::assertEquals('LOCATE(substring_column, string_column, 1)', $this->_platform->getLocateExpression('string_column', 'substring_column', 1));
349
        self::assertEquals('SUBSTR(column, 5)', $this->_platform->getSubstringExpression('column', 5));
350
        self::assertEquals('SUBSTR(column, 5, 2)', $this->_platform->getSubstringExpression('column', 5, 2));
351
    }
352
353 View Code Duplication
    public function testModifiesLimitQuery()
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...
354
    {
355
        self::assertEquals(
356
            'SELECT * FROM user',
357
            $this->_platform->modifyLimitQuery('SELECT * FROM user', null, null)
358
        );
359
360
        self::assertEquals(
361
            'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM <= 10',
362
            $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0)
363
        );
364
365
        self::assertEquals(
366
            'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM <= 10',
367
            $this->_platform->modifyLimitQuery('SELECT * FROM user', 10)
368
        );
369
370
        self::assertEquals(
371
            'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM >= 6 AND db22.DC_ROWNUM <= 15',
372
            $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 5)
373
        );
374
        self::assertEquals(
375
            'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM >= 6 AND db22.DC_ROWNUM <= 5',
376
            $this->_platform->modifyLimitQuery('SELECT * FROM user', 0, 5)
377
        );
378
    }
379
380
    public function testPrefersIdentityColumns()
381
    {
382
        self::assertTrue($this->_platform->prefersIdentityColumns());
383
    }
384
385
    public function testSupportsIdentityColumns()
386
    {
387
        self::assertTrue($this->_platform->supportsIdentityColumns());
388
    }
389
390
    public function testDoesNotSupportSavePoints()
391
    {
392
        self::assertFalse($this->_platform->supportsSavepoints());
393
    }
394
395
    public function testDoesNotSupportReleasePoints()
396
    {
397
        self::assertFalse($this->_platform->supportsReleaseSavepoints());
398
    }
399
400
    public function testDoesNotSupportCreateDropDatabase()
401
    {
402
        self::assertFalse($this->_platform->supportsCreateDropDatabase());
403
    }
404
405
    public function testReturnsSQLResultCasing()
406
    {
407
        self::assertSame('COL', $this->_platform->getSQLResultCasing('cOl'));
408
    }
409
410
    protected function getBinaryDefaultLength()
411
    {
412
        return 1;
413
    }
414
415
    protected function getBinaryMaxLength()
416
    {
417
        return 32704;
418
    }
419
420 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...
421
    {
422
        self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array()));
423
        self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
424
        self::assertSame('VARBINARY(32704)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 32704)));
425
        self::assertSame('BLOB(1M)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 32705)));
426
427
        self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
428
        self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
429
        self::assertSame('BINARY(32704)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 32704)));
430
        self::assertSame('BLOB(1M)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 32705)));
431
    }
432
433
    /**
434
     * @group DBAL-234
435
     */
436
    protected function getAlterTableRenameIndexSQL()
437
    {
438
        return array(
439
            'RENAME INDEX idx_foo TO idx_bar',
440
        );
441
    }
442
443
    /**
444
     * @group DBAL-234
445
     */
446
    protected function getQuotedAlterTableRenameIndexSQL()
447
    {
448
        return array(
449
            'RENAME INDEX "create" TO "select"',
450
            'RENAME INDEX "foo" TO "bar"',
451
        );
452
    }
453
454
    /**
455
     * {@inheritdoc}
456
     */
457 View Code Duplication
    protected function getQuotedAlterTableRenameColumnSQL()
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...
458
    {
459
        return array(
460
            'ALTER TABLE mytable ' .
461
            'RENAME COLUMN unquoted1 TO unquoted ' .
462
            'RENAME COLUMN unquoted2 TO "where" ' .
463
            'RENAME COLUMN unquoted3 TO "foo" ' .
464
            'RENAME COLUMN "create" TO reserved_keyword ' .
465
            'RENAME COLUMN "table" TO "from" ' .
466
            'RENAME COLUMN "select" TO "bar" ' .
467
            'RENAME COLUMN quoted1 TO quoted ' .
468
            'RENAME COLUMN quoted2 TO "and" ' .
469
            'RENAME COLUMN quoted3 TO "baz"'
470
        );
471
    }
472
473
    /**
474
     * {@inheritdoc}
475
     */
476
    protected function getQuotedAlterTableChangeColumnLengthSQL()
477
    {
478
        $this->markTestIncomplete('Not implemented yet');
479
    }
480
481
    /**
482
     * @group DBAL-807
483
     */
484
    protected function getAlterTableRenameIndexInSchemaSQL()
485
    {
486
        return array(
487
            'RENAME INDEX myschema.idx_foo TO idx_bar',
488
        );
489
    }
490
491
    /**
492
     * @group DBAL-807
493
     */
494
    protected function getQuotedAlterTableRenameIndexInSchemaSQL()
495
    {
496
        return array(
497
            'RENAME INDEX "schema"."create" TO "select"',
498
            'RENAME INDEX "schema"."foo" TO "bar"',
499
        );
500
    }
501
502
    /**
503
     * @group DBAL-423
504
     */
505
    public function testReturnsGuidTypeDeclarationSQL()
506
    {
507
        self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
508
    }
509
510
    /**
511
     * {@inheritdoc}
512
     */
513
    public function getAlterTableRenameColumnSQL()
514
    {
515
        return array(
516
            'ALTER TABLE foo RENAME COLUMN bar TO baz',
517
        );
518
    }
519
520
    /**
521
     * {@inheritdoc}
522
     */
523 View Code Duplication
    protected function getQuotesTableIdentifiersInAlterTableSQL()
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...
524
    {
525
        return array(
526
            'ALTER TABLE "foo" DROP FOREIGN KEY fk1',
527
            'ALTER TABLE "foo" DROP FOREIGN KEY fk2',
528
            'ALTER TABLE "foo" ' .
529
            'ADD COLUMN bloo INTEGER NOT NULL WITH DEFAULT ' .
530
            'DROP COLUMN baz ' .
531
            'ALTER COLUMN bar DROP NOT NULL ' .
532
            'RENAME COLUMN id TO war',
533
            'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE "foo"\')',
534
            'RENAME TABLE "foo" TO "table"',
535
            'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
536
            'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
537
        );
538
    }
539
540
    /**
541
     * {@inheritdoc}
542
     */
543
    protected function getCommentOnColumnSQL()
544
    {
545
        return array(
546
            'COMMENT ON COLUMN foo.bar IS \'comment\'',
547
            'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'',
548
            'COMMENT ON COLUMN "select"."from" IS \'comment\'',
549
        );
550
    }
551
552
    /**
553
     * @group DBAL-944
554
     *
555
     * @dataProvider getGeneratesAlterColumnSQL
556
     */
557
    public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $expectedSQLClause = null)
558
    {
559
        $tableDiff = new TableDiff('foo');
560
        $tableDiff->fromTable = new Table('foo');
561
        $tableDiff->changedColumns['bar'] = new ColumnDiff('bar', $column, array($changedProperty));
562
563
        $expectedSQL = array();
564
565
        if (null !== $expectedSQLClause) {
566
            $expectedSQL[] = 'ALTER TABLE foo ALTER COLUMN bar ' . $expectedSQLClause;
567
        }
568
569
        $expectedSQL[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE foo')";
570
571
        self::assertSame($expectedSQL, $this->_platform->getAlterTableSQL($tableDiff));
572
    }
573
574
    /**
575
     * @return array
576
     */
577
    public function getGeneratesAlterColumnSQL()
578
    {
579
        return array(
580
            array(
581
                'columnDefinition',
582
                new Column('bar', Type::getType('decimal'), array('columnDefinition' => 'MONEY NOT NULL')),
583
                'MONEY NOT NULL'
584
            ),
585
            array(
586
                'type',
587
                new Column('bar', Type::getType('integer')),
588
                'SET DATA TYPE INTEGER'
589
            ),
590
            array(
591
                'length',
592
                new Column('bar', Type::getType('string'), array('length' => 100)),
593
                'SET DATA TYPE VARCHAR(100)'
594
            ),
595
            array(
596
                'precision',
597
                new Column('bar', Type::getType('decimal'), array('precision' => 10, 'scale' => 2)),
598
                'SET DATA TYPE NUMERIC(10, 2)'
599
            ),
600
            array(
601
                'scale',
602
                new Column('bar', Type::getType('decimal'), array('precision' => 5, 'scale' => 4)),
603
                'SET DATA TYPE NUMERIC(5, 4)'
604
            ),
605
            array(
606
                'fixed',
607
                new Column('bar', Type::getType('string'), array('length' => 20, 'fixed' => true)),
608
                'SET DATA TYPE CHAR(20)'
609
            ),
610
            array(
611
                'notnull',
612
                new Column('bar', Type::getType('string'), array('notnull' => true)),
613
                'SET NOT NULL'
614
            ),
615
            array(
616
                'notnull',
617
                new Column('bar', Type::getType('string'), array('notnull' => false)),
618
                'DROP NOT NULL'
619
            ),
620
            array(
621
                'default',
622
                new Column('bar', Type::getType('string'), array('default' => 'foo')),
623
                "SET DEFAULT 'foo'"
624
            ),
625
            array(
626
                'default',
627
                new Column('bar', Type::getType('integer'), array('autoincrement' => true, 'default' => 666)),
628
                null
629
            ),
630
            array(
631
                'default',
632
                new Column('bar', Type::getType('string')),
633
                "DROP DEFAULT"
634
            ),
635
        );
636
    }
637
638
    /**
639
     * {@inheritdoc}
640
     */
641
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
642
    {
643
        return 'CONSTRAINT "select" UNIQUE (foo)';
644
    }
645
646
    /**
647
     * {@inheritdoc}
648
     */
649
    protected function getQuotesReservedKeywordInIndexDeclarationSQL()
650
    {
651
        return ''; // not supported by this platform
652
    }
653
654
    /**
655
     * {@inheritdoc}
656
     */
657
    protected function getQuotesReservedKeywordInTruncateTableSQL()
658
    {
659
        return 'TRUNCATE "select" IMMEDIATE';
660
    }
661
662
    /**
663
     * {@inheritdoc}
664
     */
665
    protected function supportsInlineIndexDeclaration()
666
    {
667
        return false;
668
    }
669
670
    /**
671
     * {@inheritdoc}
672
     */
673
    protected function supportsCommentOnStatement()
674
    {
675
        return true;
676
    }
677
678
    /**
679
     * {@inheritdoc}
680
     */
681
    protected function getAlterStringToFixedStringSQL()
682
    {
683
        return array(
684
            'ALTER TABLE mytable ALTER COLUMN name SET DATA TYPE CHAR(2)',
685
            'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE mytable\')',
686
        );
687
    }
688
689
    /**
690
     * {@inheritdoc}
691
     */
692
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
693
    {
694
        return array(
695
            'RENAME INDEX idx_foo TO idx_foo_renamed',
696
        );
697
    }
698
699
    /**
700
     * @group DBAL-2436
701
     */
702
    public function testQuotesTableNameInListTableColumnsSQL()
703
    {
704
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
705
    }
706
707
    /**
708
     * @group DBAL-2436
709
     */
710
    public function testQuotesTableNameInListTableIndexesSQL()
711
    {
712
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
713
    }
714
715
    /**
716
     * @group DBAL-2436
717
     */
718
    public function testQuotesTableNameInListTableForeignKeysSQL()
719
    {
720
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
721
    }
722
}
723