Completed
Push — master ( 89a52c...c0f6d4 )
by Marco
19s queued 13s
created

testReturnsBinaryTypeLongerThanMaxDeclarationSQL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Platforms;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Schema\Comparator;
7
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
8
use Doctrine\DBAL\Schema\Index;
9
use Doctrine\DBAL\Schema\Table;
10
use Doctrine\DBAL\Schema\TableDiff;
11
use Doctrine\DBAL\TransactionIsolationLevel;
12
use function array_shift;
13
14
abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
15
{
16
    public function testModifyLimitQueryWitoutLimit()
17
    {
18
        $sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null , 10);
19
        self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10',$sql);
20
    }
21
22
    public function testGenerateMixedCaseTableCreate()
23
    {
24
        $table = new Table("Foo");
25
        $table->addColumn("Bar", "integer");
26
27
        $sql = $this->_platform->getCreateTableSQL($table);
28
        self::assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql));
29
    }
30
31
    public function getGenerateTableSql()
32
    {
33
        return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB';
34
    }
35
36
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
37
    {
38
        return array(
39
            'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
40
        );
41
    }
42
43
    public function getGenerateAlterTableSql()
44
    {
45
        return array(
46
            "ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL"
47
        );
48
    }
49
50
    public function testGeneratesSqlSnippets()
51
    {
52
        self::assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
53
        self::assertEquals('`', $this->_platform->getIdentifierQuoteCharacter(), 'Quote character is not correct');
54
        self::assertEquals('CONCAT(column1, column2, column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation function is not correct');
55
    }
56
57
    public function testGeneratesTransactionsCommands()
58
    {
59
        self::assertEquals(
60
            'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
61
            $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED),
62
            ''
63
        );
64
        self::assertEquals(
65
            'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
66
            $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED)
67
        );
68
        self::assertEquals(
69
            'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ',
70
            $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ)
71
        );
72
        self::assertEquals(
73
            'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE',
74
            $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE)
75
        );
76
    }
77
78
79
    public function testGeneratesDDLSnippets()
80
    {
81
        self::assertEquals('SHOW DATABASES', $this->_platform->getListDatabasesSQL());
82
        self::assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
83
        self::assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
84
        self::assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
85
    }
86
87
    public function testGeneratesTypeDeclarationForIntegers()
88
    {
89
        self::assertEquals(
90
            'INT',
91
            $this->_platform->getIntegerTypeDeclarationSQL(array())
92
        );
93
        self::assertEquals(
94
            'INT AUTO_INCREMENT',
95
            $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
96
        ));
97
        self::assertEquals(
98
            'INT AUTO_INCREMENT',
99
            $this->_platform->getIntegerTypeDeclarationSQL(
100
                array('autoincrement' => true, 'primary' => true)
101
        ));
102
    }
103
104
    public function testGeneratesTypeDeclarationForStrings()
105
    {
106
        self::assertEquals(
107
            'CHAR(10)',
108
            $this->_platform->getVarcharTypeDeclarationSQL(
109
                array('length' => 10, 'fixed' => true)
110
        ));
111
        self::assertEquals(
112
            'VARCHAR(50)',
113
            $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
114
            'Variable string declaration is not correct'
115
        );
116
        self::assertEquals(
117
            'VARCHAR(255)',
118
            $this->_platform->getVarcharTypeDeclarationSQL(array()),
119
            'Long string declaration is not correct'
120
        );
121
    }
122
123
    public function testPrefersIdentityColumns()
124
    {
125
        self::assertTrue($this->_platform->prefersIdentityColumns());
126
    }
127
128
    public function testSupportsIdentityColumns()
129
    {
130
        self::assertTrue($this->_platform->supportsIdentityColumns());
131
    }
132
133
    public function testDoesSupportSavePoints()
134
    {
135
        self::assertTrue($this->_platform->supportsSavepoints());
136
    }
137
138
    public function getGenerateIndexSql()
139
    {
140
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
141
    }
142
143
    public function getGenerateUniqueIndexSql()
144
    {
145
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
146
    }
147
148
    public function getGenerateForeignKeySql()
149
    {
150
        return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
151
    }
152
153
    /**
154
     * @group DBAL-126
155
     */
156
    public function testUniquePrimaryKey()
157
    {
158
        $keyTable = new Table("foo");
159
        $keyTable->addColumn("bar", "integer");
160
        $keyTable->addColumn("baz", "string");
161
        $keyTable->setPrimaryKey(array("bar"));
162
        $keyTable->addUniqueIndex(array("baz"));
163
164
        $oldTable = new Table("foo");
165
        $oldTable->addColumn("bar", "integer");
166
        $oldTable->addColumn("baz", "string");
167
168
        $c = new \Doctrine\DBAL\Schema\Comparator;
169
        $diff = $c->diffTable($oldTable, $keyTable);
170
171
        $sql = $this->_platform->getAlterTableSQL($diff);
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

171
        $sql = $this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $diff);
Loading history...
172
173
        self::assertEquals(array(
174
            "ALTER TABLE foo ADD PRIMARY KEY (bar)",
175
            "CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)",
176
        ), $sql);
177
    }
178
179
    public function testModifyLimitQuery()
180
    {
181
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
182
        self::assertEquals('SELECT * FROM user LIMIT 10', $sql);
183
    }
184
185
    public function testModifyLimitQueryWithEmptyOffset()
186
    {
187
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
188
        self::assertEquals('SELECT * FROM user LIMIT 10', $sql);
189
    }
190
191
    /**
192
     * @group DDC-118
193
     */
194
    public function testGetDateTimeTypeDeclarationSql()
195
    {
196
        self::assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => false)));
197
        self::assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true)));
198
        self::assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array()));
199
    }
200
201
    public function getCreateTableColumnCommentsSQL()
202
    {
203
        return array("CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
204
    }
205
206
    public function getAlterTableColumnCommentsSQL()
207
    {
208
        return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'");
209
    }
210
211
    public function getCreateTableColumnTypeCommentsSQL()
212
    {
213
        return array("CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
214
    }
215
216
    /**
217
     * @group DBAL-237
218
     */
219
    public function testChangeIndexWithForeignKeys()
220
    {
221
        $index = new Index("idx", array("col"), false);
222
        $unique = new Index("uniq", array("col"), true);
223
224
        $diff = new TableDiff("test", array(), array(), array(), array($unique), array(), array($index));
225
        $sql = $this->_platform->getAlterTableSQL($diff);
226
        self::assertEquals(array("ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)"), $sql);
227
228
        $diff = new TableDiff("test", array(), array(), array(), array($index), array(), array($unique));
229
        $sql = $this->_platform->getAlterTableSQL($diff);
230
        self::assertEquals(array("ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"), $sql);
231
    }
232
233
    protected function getQuotedColumnInPrimaryKeySQL()
234
    {
235
        return array(
236
            'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
237
        );
238
    }
239
240
    protected function getQuotedColumnInIndexSQL()
241
    {
242
        return array(
243
            'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
244
        );
245
    }
246
247
    protected function getQuotedNameInIndexSQL()
248
    {
249
        return array(
250
            'CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
251
        );
252
    }
253
254
    protected function getQuotedColumnInForeignKeySQL()
255
    {
256
        return array(
257
            'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
258
            'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foreign` (`create`, bar, `foo-bar`)',
259
            'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES foo (`create`, bar, `foo-bar`)',
260
            'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foo-bar` (`create`, bar, `foo-bar`)',
261
        );
262
    }
263
264
    public function testCreateTableWithFulltextIndex()
265
    {
266
        $table = new Table('fulltext_table');
267
        $table->addOption('engine', 'MyISAM');
268
        $table->addColumn('text', 'text');
269
        $table->addIndex(array('text'), 'fulltext_text');
270
271
        $index = $table->getIndex('fulltext_text');
272
        $index->addFlag('fulltext');
273
274
        $sql = $this->_platform->getCreateTableSQL($table);
275
        self::assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
276
    }
277
278
    public function testCreateTableWithSpatialIndex()
279
    {
280
        $table = new Table('spatial_table');
281
        $table->addOption('engine', 'MyISAM');
282
        $table->addColumn('point', 'text'); // This should be a point type
283
        $table->addIndex(array('point'), 'spatial_text');
284
285
        $index = $table->getIndex('spatial_text');
286
        $index->addFlag('spatial');
287
288
        $sql = $this->_platform->getCreateTableSQL($table);
289
        self::assertEquals(array('CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
290
    }
291
292
    public function testClobTypeDeclarationSQL()
293
    {
294
        self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1)));
295
        self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 255)));
296
        self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 256)));
297
        self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65535)));
298
        self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65536)));
299
        self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777215)));
300
        self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777216)));
301
        self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array()));
302
    }
303
304
    public function testBlobTypeDeclarationSQL()
305
    {
306
        self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 1)));
307
        self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 255)));
308
        self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 256)));
309
        self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65535)));
310
        self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65536)));
311
        self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777215)));
312
        self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777216)));
313
        self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array()));
314
    }
315
316
    /**
317
     * @group DBAL-400
318
     */
319
    public function testAlterTableAddPrimaryKey()
320
    {
321
        $table = new Table('alter_table_add_pk');
322
        $table->addColumn('id', 'integer');
323
        $table->addColumn('foo', 'integer');
324
        $table->addIndex(array('id'), 'idx_id');
325
326
        $comparator = new Comparator();
327
        $diffTable  = clone $table;
328
329
        $diffTable->dropIndex('idx_id');
330
        $diffTable->setPrimaryKey(array('id'));
331
332
        self::assertEquals(
333
            array('DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'),
334
            $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

334
            $this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
335
        );
336
    }
337
338
    /**
339
     * @group DBAL-1132
340
     */
341
    public function testAlterPrimaryKeyWithAutoincrementColumn()
342
    {
343
        $table = new Table("alter_primary_key");
344
        $table->addColumn('id', 'integer', array('autoincrement' => true));
345
        $table->addColumn('foo', 'integer');
346
        $table->setPrimaryKey(array('id'));
347
348
        $comparator = new Comparator();
349
        $diffTable = clone $table;
350
351
        $diffTable->dropPrimaryKey();
352
        $diffTable->setPrimaryKey(array('foo'));
353
354
        self::assertEquals(
355
            array(
356
                'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL',
357
                'ALTER TABLE alter_primary_key DROP PRIMARY KEY',
358
                'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)'
359
            ),
360
            $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

360
            $this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
361
        );
362
    }
363
364
    /**
365
     * @group DBAL-464
366
     */
367
    public function testDropPrimaryKeyWithAutoincrementColumn()
368
    {
369
        $table = new Table("drop_primary_key");
370
        $table->addColumn('id', 'integer', array('autoincrement' => true));
371
        $table->addColumn('foo', 'integer');
372
        $table->addColumn('bar', 'integer');
373
        $table->setPrimaryKey(array('id', 'foo'));
374
375
        $comparator = new Comparator();
376
        $diffTable = clone $table;
377
378
        $diffTable->dropPrimaryKey();
379
380
        self::assertEquals(
381
            array(
382
                'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL',
383
                'ALTER TABLE drop_primary_key DROP PRIMARY KEY'
384
            ),
385
            $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

385
            $this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
386
        );
387
    }
388
389
    /**
390
     * @group DBAL-2302
391
     */
392
    public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn()
393
    {
394
        $table = new Table("tbl");
395
        $table->addColumn('id', 'integer', array('autoincrement' => true));
396
        $table->addColumn('foo', 'integer');
397
        $table->addColumn('bar', 'integer');
398
        $table->setPrimaryKey(array('id', 'foo'));
399
400
        $comparator = new Comparator();
401
        $diffTable = clone $table;
402
403
        $diffTable->dropPrimaryKey();
404
        $diffTable->setPrimaryKey(array('id'));
405
406
        self::assertSame(
407
            array(
408
                'ALTER TABLE tbl MODIFY id INT NOT NULL',
409
                'ALTER TABLE tbl DROP PRIMARY KEY',
410
                'ALTER TABLE tbl ADD PRIMARY KEY (id)',
411
            ),
412
            $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

412
            $this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
413
        );
414
    }
415
416
    /**
417
     * @group DBAL-2302
418
     */
419
    public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn()
420
    {
421
        $table = new Table("tbl");
422
        $table->addColumn('id', 'integer', array('autoincrement' => true));
423
        $table->addColumn('foo', 'integer');
424
        $table->addColumn('bar', 'integer');
425
        $table->setPrimaryKey(array('id'));
426
427
        $comparator = new Comparator();
428
        $diffTable = clone $table;
429
430
        $diffTable->dropPrimaryKey();
431
        $diffTable->setPrimaryKey(array('id', 'foo'));
432
433
        self::assertSame(
434
            array(
435
                'ALTER TABLE tbl MODIFY id INT NOT NULL',
436
                'ALTER TABLE tbl DROP PRIMARY KEY',
437
                'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)',
438
            ),
439
            $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

439
            $this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
440
        );
441
    }
442
443
    /**
444
     * @group DBAL-586
445
     */
446
    public function testAddAutoIncrementPrimaryKey()
447
    {
448
        $keyTable = new Table("foo");
449
        $keyTable->addColumn("id", "integer", array('autoincrement' => true));
450
        $keyTable->addColumn("baz", "string");
451
        $keyTable->setPrimaryKey(array("id"));
452
453
        $oldTable = new Table("foo");
454
        $oldTable->addColumn("baz", "string");
455
456
        $c = new \Doctrine\DBAL\Schema\Comparator;
457
        $diff = $c->diffTable($oldTable, $keyTable);
458
459
        $sql = $this->_platform->getAlterTableSQL($diff);
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

459
        $sql = $this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $diff);
Loading history...
460
461
        self::assertEquals(array(
462
            "ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)",
463
        ), $sql);
464
    }
465
466
    public function testNamedPrimaryKey()
467
    {
468
        $diff = new TableDiff('mytable');
469
        $diff->changedIndexes['foo_index'] = new Index('foo_index', array('foo'), true, true);
470
471
        $sql = $this->_platform->getAlterTableSQL($diff);
472
473
        self::assertEquals(array(
474
            "ALTER TABLE mytable DROP PRIMARY KEY",
475
            "ALTER TABLE mytable ADD PRIMARY KEY (foo)",
476
        ), $sql);
477
    }
478
479
    public function testAlterPrimaryKeyWithNewColumn()
480
    {
481
        $table = new Table("yolo");
482
        $table->addColumn('pkc1', 'integer');
483
        $table->addColumn('col_a', 'integer');
484
        $table->setPrimaryKey(array('pkc1'));
485
486
        $comparator = new Comparator();
487
        $diffTable = clone $table;
488
489
        $diffTable->addColumn('pkc2', 'integer');
490
        $diffTable->dropPrimaryKey();
491
        $diffTable->setPrimaryKey(array('pkc1', 'pkc2'));
492
493
        self::assertSame(
494
            array(
495
                'ALTER TABLE yolo DROP PRIMARY KEY',
496
                'ALTER TABLE yolo ADD pkc2 INT NOT NULL',
497
                'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)',
498
            ),
499
            $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

499
            $this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
500
        );
501
    }
502
503
    public function testInitializesDoctrineTypeMappings()
504
    {
505
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary'));
506
        self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary'));
507
508
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary'));
509
        self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary'));
510
    }
511
512
    protected function getBinaryMaxLength()
513
    {
514
        return 65535;
515
    }
516
517
    public function testReturnsBinaryTypeDeclarationSQL()
518
    {
519
        self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array()));
520
        self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
521
        self::assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65535)));
522
523
        self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
524
        self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
525
        self::assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65535)));
526
    }
527
528
    /**
529
     * @group legacy
530
     * @expectedDeprecation Binary field length 65536 is greater than supported by the platform (65535)
531
     * @expectedDeprecation Binary field length 16777215 is greater than supported by the platform (65535)
532
     * @expectedDeprecation Binary field length 16777216 is greater than supported by the platform (65535)
533
     */
534
    public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL()
535
    {
536
        self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 65536]));
537
        self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 16777215]));
538
        self::assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 16777216]));
539
540
        self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65536]));
541
        self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777215]));
542
        self::assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777216]));
543
    }
544
545
    public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines()
546
    {
547
        $table = new Table("foreign_table");
548
        $table->addColumn('id', 'integer');
549
        $table->addColumn('fk_id', 'integer');
550
        $table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id'));
551
        $table->setPrimaryKey(array('id'));
552
        $table->addOption('engine', 'MyISAM');
553
554
        self::assertSame(
555
            array('CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'),
556
            $this->_platform->getCreateTableSQL(
557
                $table,
558
                AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS
559
            )
560
        );
561
562
        $table = clone $table;
563
        $table->addOption('engine', 'InnoDB');
564
565
        self::assertSame(
566
            array(
567
                'CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
568
                'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)'
569
            ),
570
            $this->_platform->getCreateTableSQL(
571
                $table,
572
                AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS
573
            )
574
        );
575
    }
576
577
    public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines()
578
    {
579
        $table = new Table("foreign_table");
580
        $table->addColumn('id', 'integer');
581
        $table->addColumn('fk_id', 'integer');
582
        $table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id'));
583
        $table->setPrimaryKey(array('id'));
584
        $table->addOption('engine', 'MyISAM');
585
586
        $addedForeignKeys   = array(new ForeignKeyConstraint(array('fk_id'), 'foo', array('id'), 'fk_add'));
587
        $changedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'bar', array('id'), 'fk_change'));
588
        $removedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'baz', array('id'), 'fk_remove'));
589
590
        $tableDiff = new TableDiff('foreign_table');
591
        $tableDiff->fromTable = $table;
592
        $tableDiff->addedForeignKeys = $addedForeignKeys;
593
        $tableDiff->changedForeignKeys = $changedForeignKeys;
594
        $tableDiff->removedForeignKeys = $removedForeignKeys;
595
596
        self::assertEmpty($this->_platform->getAlterTableSQL($tableDiff));
597
598
        $table->addOption('engine', 'InnoDB');
599
600
        $tableDiff = new TableDiff('foreign_table');
601
        $tableDiff->fromTable = $table;
602
        $tableDiff->addedForeignKeys = $addedForeignKeys;
603
        $tableDiff->changedForeignKeys = $changedForeignKeys;
604
        $tableDiff->removedForeignKeys = $removedForeignKeys;
605
606
        self::assertSame(
607
            array(
608
                'ALTER TABLE foreign_table DROP FOREIGN KEY fk_remove',
609
                'ALTER TABLE foreign_table DROP FOREIGN KEY fk_change',
610
                'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)',
611
                'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)',
612
            ),
613
            $this->_platform->getAlterTableSQL($tableDiff)
614
        );
615
    }
616
617
    /**
618
     * @group DBAL-234
619
     */
620
    protected function getAlterTableRenameIndexSQL()
621
    {
622
        return array(
623
            'DROP INDEX idx_foo ON mytable',
624
            'CREATE INDEX idx_bar ON mytable (id)',
625
        );
626
    }
627
628
    /**
629
     * @group DBAL-234
630
     */
631
    protected function getQuotedAlterTableRenameIndexSQL()
632
    {
633
        return array(
634
            'DROP INDEX `create` ON `table`',
635
            'CREATE INDEX `select` ON `table` (id)',
636
            'DROP INDEX `foo` ON `table`',
637
            'CREATE INDEX `bar` ON `table` (id)',
638
        );
639
    }
640
641
    /**
642
     * @group DBAL-807
643
     */
644
    protected function getAlterTableRenameIndexInSchemaSQL()
645
    {
646
        return array(
647
            'DROP INDEX idx_foo ON myschema.mytable',
648
            'CREATE INDEX idx_bar ON myschema.mytable (id)',
649
        );
650
    }
651
652
    /**
653
     * @group DBAL-807
654
     */
655
    protected function getQuotedAlterTableRenameIndexInSchemaSQL()
656
    {
657
        return array(
658
            'DROP INDEX `create` ON `schema`.`table`',
659
            'CREATE INDEX `select` ON `schema`.`table` (id)',
660
            'DROP INDEX `foo` ON `schema`.`table`',
661
            'CREATE INDEX `bar` ON `schema`.`table` (id)',
662
        );
663
    }
664
665
    protected function getQuotesDropForeignKeySQL()
666
    {
667
        return 'ALTER TABLE `table` DROP FOREIGN KEY `select`';
668
    }
669
670
    protected function getQuotesDropConstraintSQL()
671
    {
672
        return 'ALTER TABLE `table` DROP CONSTRAINT `select`';
673
    }
674
675
    public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
676
    {
677
        $table = new Table("text_blob_default_value");
678
        $table->addColumn('def_text', 'text', array('default' => 'def'));
679
        $table->addColumn('def_text_null', 'text', array('notnull' => false, 'default' => 'def'));
680
        $table->addColumn('def_blob', 'blob', array('default' => 'def'));
681
        $table->addColumn('def_blob_null', 'blob', array('notnull' => false, 'default' => 'def'));
682
683
        self::assertSame(
684
            array('CREATE TABLE text_blob_default_value (def_text LONGTEXT NOT NULL, def_text_null LONGTEXT DEFAULT NULL, def_blob LONGBLOB NOT NULL, def_blob_null LONGBLOB DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'),
685
            $this->_platform->getCreateTableSQL($table)
686
        );
687
688
        $diffTable = clone $table;
689
        $diffTable->changeColumn('def_text', array('default' => null));
690
        $diffTable->changeColumn('def_text_null', array('default' => null));
691
        $diffTable->changeColumn('def_blob', array('default' => null));
692
        $diffTable->changeColumn('def_blob_null', array('default' => null));
693
694
        $comparator = new Comparator();
695
696
        self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)));
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

696
        self::assertEmpty($this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable)));
Loading history...
697
    }
698
699
    /**
700
     * {@inheritdoc}
701
     */
702
    protected function getQuotedAlterTableRenameColumnSQL()
703
    {
704
        return array(
705
            "ALTER TABLE mytable " .
706
            "CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " .
707
            "CHANGE unquoted2 `where` INT NOT NULL COMMENT 'Unquoted 2', " .
708
            "CHANGE unquoted3 `foo` INT NOT NULL COMMENT 'Unquoted 3', " .
709
            "CHANGE `create` reserved_keyword INT NOT NULL COMMENT 'Reserved keyword 1', " .
710
            "CHANGE `table` `from` INT NOT NULL COMMENT 'Reserved keyword 2', " .
711
            "CHANGE `select` `bar` INT NOT NULL COMMENT 'Reserved keyword 3', " .
712
            "CHANGE quoted1 quoted INT NOT NULL COMMENT 'Quoted 1', " .
713
            "CHANGE quoted2 `and` INT NOT NULL COMMENT 'Quoted 2', " .
714
            "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'"
715
        );
716
    }
717
718
    /**
719
     * {@inheritdoc}
720
     */
721
    protected function getQuotedAlterTableChangeColumnLengthSQL()
722
    {
723
        return array(
724
            "ALTER TABLE mytable " .
725
            "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " .
726
            "CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " .
727
            "CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " .
728
            "CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " .
729
            "CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " .
730
            "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'"
731
        );
732
    }
733
734
    /**
735
     * @group DBAL-423
736
     */
737
    public function testReturnsGuidTypeDeclarationSQL()
738
    {
739
        self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
740
    }
741
742
    /**
743
     * {@inheritdoc}
744
     */
745
    public function getAlterTableRenameColumnSQL()
746
    {
747
        return array(
748
            "ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'",
749
        );
750
    }
751
752
    /**
753
     * {@inheritdoc}
754
     */
755
    protected function getQuotesTableIdentifiersInAlterTableSQL()
756
    {
757
        return array(
758
            'ALTER TABLE `foo` DROP FOREIGN KEY fk1',
759
            'ALTER TABLE `foo` DROP FOREIGN KEY fk2',
760
            'ALTER TABLE `foo` RENAME TO `table`, ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' .
761
            'CHANGE id war INT NOT NULL',
762
            'ALTER TABLE `table` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
763
            'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
764
        );
765
    }
766
767
    /**
768
     * {@inheritdoc}
769
     */
770
    protected function getCommentOnColumnSQL()
771
    {
772
        return array(
773
            "COMMENT ON COLUMN foo.bar IS 'comment'",
774
            "COMMENT ON COLUMN `Foo`.`BAR` IS 'comment'",
775
            "COMMENT ON COLUMN `select`.`from` IS 'comment'",
776
        );
777
    }
778
779
    /**
780
     * {@inheritdoc}
781
     */
782
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
783
    {
784
        return 'CONSTRAINT `select` UNIQUE (foo)';
785
    }
786
787
    /**
788
     * {@inheritdoc}
789
     */
790
    protected function getQuotesReservedKeywordInIndexDeclarationSQL()
791
    {
792
        return 'INDEX `select` (foo)';
793
    }
794
795
    /**
796
     * {@inheritdoc}
797
     */
798
    protected function getQuotesReservedKeywordInTruncateTableSQL()
799
    {
800
        return 'TRUNCATE `select`';
801
    }
802
803
    /**
804
     * {@inheritdoc}
805
     */
806
    protected function getAlterStringToFixedStringSQL()
807
    {
808
        return array(
809
            'ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL',
810
        );
811
    }
812
813
    /**
814
     * {@inheritdoc}
815
     */
816
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
817
    {
818
        return array(
819
            'ALTER TABLE mytable DROP FOREIGN KEY fk_foo',
820
            'DROP INDEX idx_foo ON mytable',
821
            'CREATE INDEX idx_foo_renamed ON mytable (foo)',
822
            'ALTER TABLE mytable ADD CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id)',
823
        );
824
    }
825
826
    /**
827
     * {@inheritdoc}
828
     */
829
    public function getGeneratesDecimalTypeDeclarationSQL()
830
    {
831
        return array(
832
            array(array(), 'NUMERIC(10, 0)'),
833
            array(array('unsigned' => true), 'NUMERIC(10, 0) UNSIGNED'),
834
            array(array('unsigned' => false), 'NUMERIC(10, 0)'),
835
            array(array('precision' => 5), 'NUMERIC(5, 0)'),
836
            array(array('scale' => 5), 'NUMERIC(10, 5)'),
837
            array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'),
838
        );
839
    }
840
841
    /**
842
     * {@inheritdoc}
843
     */
844
    public function getGeneratesFloatDeclarationSQL()
845
    {
846
        return array(
847
            array(array(), 'DOUBLE PRECISION'),
848
            array(array('unsigned' => true), 'DOUBLE PRECISION UNSIGNED'),
849
            array(array('unsigned' => false), 'DOUBLE PRECISION'),
850
            array(array('precision' => 5), 'DOUBLE PRECISION'),
851
            array(array('scale' => 5), 'DOUBLE PRECISION'),
852
            array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'),
853
        );
854
    }
855
856
    /**
857
     * @group DBAL-2436
858
     */
859
    public function testQuotesTableNameInListTableIndexesSQL()
860
    {
861
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db'), '', true);
862
    }
863
864
    /**
865
     * @group DBAL-2436
866
     */
867
    public function testQuotesDatabaseNameInListTableIndexesSQL()
868
    {
869
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\"), '', true);
870
    }
871
872
    /**
873
     * @group DBAL-2436
874
     */
875
    public function testQuotesDatabaseNameInListViewsSQL()
876
    {
877
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListViewsSQL("Foo'Bar\\"), '', true);
878
    }
879
880
    /**
881
     * @group DBAL-2436
882
     */
883
    public function testQuotesTableNameInListTableForeignKeysSQL()
884
    {
885
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
886
    }
887
888
    /**
889
     * @group DBAL-2436
890
     */
891
    public function testQuotesDatabaseNameInListTableForeignKeysSQL()
892
    {
893
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\"), '', true);
0 ignored issues
show
Unused Code introduced by
The call to Doctrine\DBAL\Platforms\...stTableForeignKeysSQL() has too many arguments starting with 'Foo'Bar\'. ( Ignorable by Annotation )

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

893
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->/** @scrutinizer ignore-call */ getListTableForeignKeysSQL('foo_table', "Foo'Bar\\"), '', true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
894
    }
895
896
    /**
897
     * @group DBAL-2436
898
     */
899
    public function testQuotesTableNameInListTableColumnsSQL()
900
    {
901
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
902
    }
903
904
    /**
905
     * @group DBAL-2436
906
     */
907
    public function testQuotesDatabaseNameInListTableColumnsSQL()
908
    {
909
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true);
910
    }
911
912
    public function testListTableForeignKeysSQLEvaluatesDatabase()
913
    {
914
        $sql = $this->_platform->getListTableForeignKeysSQL('foo');
915
916
        self::assertContains('DATABASE()', $sql);
917
918
        $sql = $this->_platform->getListTableForeignKeysSQL('foo', 'bar');
919
920
        self::assertContains('bar', $sql);
921
        self::assertNotContains('DATABASE()', $sql);
922
    }
923
924
    public function testSupportsColumnCollation() : void
925
    {
926
        self::assertTrue($this->_platform->supportsColumnCollation());
927
    }
928
929
    public function testColumnCollationDeclarationSQL() : void
930
    {
931
        self::assertSame(
932
            'COLLATE ascii_general_ci',
933
            $this->_platform->getColumnCollationDeclarationSQL('ascii_general_ci')
934
        );
935
    }
936
937
    public function testGetCreateTableSQLWithColumnCollation() : void
938
    {
939
        $table = new Table('foo');
940
        $table->addColumn('no_collation', 'string');
941
        $table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'ascii_general_ci');
942
943
        self::assertSame(
944
            ['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE ascii_general_ci) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'],
945
            $this->_platform->getCreateTableSQL($table),
946
            'Column "no_collation" will use the default collation from the table/database and "column_collation" overwrites the collation on this column'
947
        );
948
    }
949
}
950