Passed
Push — type-registry ( f9a1df...0931f1 )
by Michael
24:09
created

testSupportsColumnCollation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Platforms;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Platforms\MySqlPlatform;
7
use Doctrine\DBAL\Schema\Comparator;
8
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
9
use Doctrine\DBAL\Schema\Index;
10
use Doctrine\DBAL\Schema\Table;
11
use Doctrine\DBAL\Schema\TableDiff;
12
use Doctrine\DBAL\TransactionIsolationLevel;
13
use function array_shift;
14
15
abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
16
{
17
    /** @var MySqlPlatform */
18
    protected $platform;
19
20
    public function testModifyLimitQueryWitoutLimit()
21
    {
22
        $sql = $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10);
23
        self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10', $sql);
24
    }
25
26
    public function testGenerateMixedCaseTableCreate()
27
    {
28
        $table = new Table('Foo');
29
        $table->addColumn('Bar', 'integer');
30
31
        $sql = $this->platform->getCreateTableSQL($table);
32
        self::assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql));
33
    }
34
35
    public function getGenerateTableSql()
36
    {
37
        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';
38
    }
39
40
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
41
    {
42
        return ['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'];
43
    }
44
45
    public function getGenerateAlterTableSql()
46
    {
47
        return ["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"];
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
    public function testGeneratesDDLSnippets()
79
    {
80
        self::assertEquals('SHOW DATABASES', $this->platform->getListDatabasesSQL());
81
        self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar'));
82
        self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar'));
83
        self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar'));
84
    }
85
86
    public function testGeneratesTypeDeclarationForIntegers()
87
    {
88
        self::assertEquals(
89
            'INT',
90
            $this->platform->getIntegerTypeDeclarationSQL([])
91
        );
92
        self::assertEquals(
93
            'INT AUTO_INCREMENT',
94
            $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true])
95
        );
96
        self::assertEquals(
97
            'INT AUTO_INCREMENT',
98
            $this->platform->getIntegerTypeDeclarationSQL(
99
                ['autoincrement' => true, 'primary' => true]
100
            )
101
        );
102
    }
103
104
    public function testGeneratesTypeDeclarationForStrings()
105
    {
106
        self::assertEquals(
107
            'CHAR(10)',
108
            $this->platform->getVarcharTypeDeclarationSQL(
109
                ['length' => 10, 'fixed' => true]
110
            )
111
        );
112
        self::assertEquals(
113
            'VARCHAR(50)',
114
            $this->platform->getVarcharTypeDeclarationSQL(['length' => 50]),
115
            'Variable string declaration is not correct'
116
        );
117
        self::assertEquals(
118
            'VARCHAR(255)',
119
            $this->platform->getVarcharTypeDeclarationSQL([]),
120
            'Long string declaration is not correct'
121
        );
122
    }
123
124
    public function testPrefersIdentityColumns()
125
    {
126
        self::assertTrue($this->platform->prefersIdentityColumns());
127
    }
128
129
    public function testSupportsIdentityColumns()
130
    {
131
        self::assertTrue($this->platform->supportsIdentityColumns());
132
    }
133
134
    public function testDoesSupportSavePoints()
135
    {
136
        self::assertTrue($this->platform->supportsSavepoints());
137
    }
138
139
    public function getGenerateIndexSql()
140
    {
141
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
142
    }
143
144
    public function getGenerateUniqueIndexSql()
145
    {
146
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
147
    }
148
149
    public function getGenerateForeignKeySql()
150
    {
151
        return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
152
    }
153
154
    /**
155
     * @group DBAL-126
156
     */
157
    public function testUniquePrimaryKey()
158
    {
159
        $keyTable = new Table('foo');
160
        $keyTable->addColumn('bar', 'integer');
161
        $keyTable->addColumn('baz', 'string');
162
        $keyTable->setPrimaryKey(['bar']);
163
        $keyTable->addUniqueIndex(['baz']);
164
165
        $oldTable = new Table('foo');
166
        $oldTable->addColumn('bar', 'integer');
167
        $oldTable->addColumn('baz', 'string');
168
169
        $c    = new Comparator();
170
        $diff = $c->diffTable($oldTable, $keyTable);
171
172
        $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

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

329
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
330
        );
331
    }
332
333
    /**
334
     * @group DBAL-1132
335
     */
336
    public function testAlterPrimaryKeyWithAutoincrementColumn()
337
    {
338
        $table = new Table('alter_primary_key');
339
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
340
        $table->addColumn('foo', 'integer');
341
        $table->setPrimaryKey(['id']);
342
343
        $comparator = new Comparator();
344
        $diffTable  = clone $table;
345
346
        $diffTable->dropPrimaryKey();
347
        $diffTable->setPrimaryKey(['foo']);
348
349
        self::assertEquals(
350
            [
351
                'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL',
352
                'ALTER TABLE alter_primary_key DROP PRIMARY KEY',
353
                'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)',
354
            ],
355
            $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

355
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
356
        );
357
    }
358
359
    /**
360
     * @group DBAL-464
361
     */
362
    public function testDropPrimaryKeyWithAutoincrementColumn()
363
    {
364
        $table = new Table('drop_primary_key');
365
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
366
        $table->addColumn('foo', 'integer');
367
        $table->addColumn('bar', 'integer');
368
        $table->setPrimaryKey(['id', 'foo']);
369
370
        $comparator = new Comparator();
371
        $diffTable  = clone $table;
372
373
        $diffTable->dropPrimaryKey();
374
375
        self::assertEquals(
376
            [
377
                'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL',
378
                'ALTER TABLE drop_primary_key DROP PRIMARY KEY',
379
            ],
380
            $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

380
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
381
        );
382
    }
383
384
    /**
385
     * @group DBAL-2302
386
     */
387
    public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn()
388
    {
389
        $table = new Table('tbl');
390
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
391
        $table->addColumn('foo', 'integer');
392
        $table->addColumn('bar', 'integer');
393
        $table->setPrimaryKey(['id', 'foo']);
394
395
        $comparator = new Comparator();
396
        $diffTable  = clone $table;
397
398
        $diffTable->dropPrimaryKey();
399
        $diffTable->setPrimaryKey(['id']);
400
401
        self::assertSame(
402
            [
403
                'ALTER TABLE tbl MODIFY id INT NOT NULL',
404
                'ALTER TABLE tbl DROP PRIMARY KEY',
405
                'ALTER TABLE tbl ADD PRIMARY KEY (id)',
406
            ],
407
            $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

407
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
408
        );
409
    }
410
411
    /**
412
     * @group DBAL-2302
413
     */
414
    public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn()
415
    {
416
        $table = new Table('tbl');
417
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
418
        $table->addColumn('foo', 'integer');
419
        $table->addColumn('bar', 'integer');
420
        $table->setPrimaryKey(['id']);
421
422
        $comparator = new Comparator();
423
        $diffTable  = clone $table;
424
425
        $diffTable->dropPrimaryKey();
426
        $diffTable->setPrimaryKey(['id', 'foo']);
427
428
        self::assertSame(
429
            [
430
                'ALTER TABLE tbl MODIFY id INT NOT NULL',
431
                'ALTER TABLE tbl DROP PRIMARY KEY',
432
                'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)',
433
            ],
434
            $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

434
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable))
Loading history...
435
        );
436
    }
437
438
    /**
439
     * @group DBAL-586
440
     */
441
    public function testAddAutoIncrementPrimaryKey()
442
    {
443
        $keyTable = new Table('foo');
444
        $keyTable->addColumn('id', 'integer', ['autoincrement' => true]);
445
        $keyTable->addColumn('baz', 'string');
446
        $keyTable->setPrimaryKey(['id']);
447
448
        $oldTable = new Table('foo');
449
        $oldTable->addColumn('baz', 'string');
450
451
        $c    = new Comparator();
452
        $diff = $c->diffTable($oldTable, $keyTable);
453
454
        $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

454
        $sql = $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $diff);
Loading history...
455
456
        self::assertEquals(['ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)'], $sql);
457
    }
458
459
    public function testNamedPrimaryKey()
460
    {
461
        $diff                              = new TableDiff('mytable');
462
        $diff->changedIndexes['foo_index'] = new Index('foo_index', ['foo'], true, true);
463
464
        $sql = $this->platform->getAlterTableSQL($diff);
465
466
        self::assertEquals([
467
            'ALTER TABLE mytable DROP PRIMARY KEY',
468
            'ALTER TABLE mytable ADD PRIMARY KEY (foo)',
469
        ], $sql);
470
    }
471
472
    public function testAlterPrimaryKeyWithNewColumn()
473
    {
474
        $table = new Table('yolo');
475
        $table->addColumn('pkc1', 'integer');
476
        $table->addColumn('col_a', 'integer');
477
        $table->setPrimaryKey(['pkc1']);
478
479
        $comparator = new Comparator();
480
        $diffTable  = clone $table;
481
482
        $diffTable->addColumn('pkc2', 'integer');
483
        $diffTable->dropPrimaryKey();
484
        $diffTable->setPrimaryKey(['pkc1', 'pkc2']);
485
486
        self::assertSame(
487
            [
488
                'ALTER TABLE yolo DROP PRIMARY KEY',
489
                'ALTER TABLE yolo ADD pkc2 INT NOT NULL',
490
                'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)',
491
            ],
492
            $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

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

689
        self::assertEmpty($this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable)));
Loading history...
690
    }
691
692
    /**
693
     * {@inheritdoc}
694
     */
695
    protected function getQuotedAlterTableRenameColumnSQL()
696
    {
697
        return ['ALTER TABLE mytable ' .
698
            "CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " .
699
            "CHANGE unquoted2 `where` INT NOT NULL COMMENT 'Unquoted 2', " .
700
            "CHANGE unquoted3 `foo` INT NOT NULL COMMENT 'Unquoted 3', " .
701
            "CHANGE `create` reserved_keyword INT NOT NULL COMMENT 'Reserved keyword 1', " .
702
            "CHANGE `table` `from` INT NOT NULL COMMENT 'Reserved keyword 2', " .
703
            "CHANGE `select` `bar` INT NOT NULL COMMENT 'Reserved keyword 3', " .
704
            "CHANGE quoted1 quoted INT NOT NULL COMMENT 'Quoted 1', " .
705
            "CHANGE quoted2 `and` INT NOT NULL COMMENT 'Quoted 2', " .
706
            "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'",
707
        ];
708
    }
709
710
    /**
711
     * {@inheritdoc}
712
     */
713
    protected function getQuotedAlterTableChangeColumnLengthSQL()
714
    {
715
        return ['ALTER TABLE mytable ' .
716
            "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " .
717
            "CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " .
718
            "CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " .
719
            "CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " .
720
            "CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " .
721
            "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'",
722
        ];
723
    }
724
725
    /**
726
     * @group DBAL-423
727
     */
728
    public function testReturnsGuidTypeDeclarationSQL()
729
    {
730
        self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([]));
731
    }
732
733
    /**
734
     * {@inheritdoc}
735
     */
736
    public function getAlterTableRenameColumnSQL()
737
    {
738
        return ["ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'"];
739
    }
740
741
    /**
742
     * {@inheritdoc}
743
     */
744
    protected function getQuotesTableIdentifiersInAlterTableSQL()
745
    {
746
        return [
747
            'ALTER TABLE `foo` DROP FOREIGN KEY fk1',
748
            'ALTER TABLE `foo` DROP FOREIGN KEY fk2',
749
            'ALTER TABLE `foo` RENAME TO `table`, ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' .
750
            'CHANGE id war INT NOT NULL',
751
            'ALTER TABLE `table` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
752
            'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
753
        ];
754
    }
755
756
    /**
757
     * {@inheritdoc}
758
     */
759
    protected function getCommentOnColumnSQL()
760
    {
761
        return [
762
            "COMMENT ON COLUMN foo.bar IS 'comment'",
763
            "COMMENT ON COLUMN `Foo`.`BAR` IS 'comment'",
764
            "COMMENT ON COLUMN `select`.`from` IS 'comment'",
765
        ];
766
    }
767
768
    /**
769
     * {@inheritdoc}
770
     */
771
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
772
    {
773
        return 'CONSTRAINT `select` UNIQUE (foo)';
774
    }
775
776
    /**
777
     * {@inheritdoc}
778
     */
779
    protected function getQuotesReservedKeywordInIndexDeclarationSQL()
780
    {
781
        return 'INDEX `select` (foo)';
782
    }
783
784
    /**
785
     * {@inheritdoc}
786
     */
787
    protected function getQuotesReservedKeywordInTruncateTableSQL()
788
    {
789
        return 'TRUNCATE `select`';
790
    }
791
792
    /**
793
     * {@inheritdoc}
794
     */
795
    protected function getAlterStringToFixedStringSQL()
796
    {
797
        return ['ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL'];
798
    }
799
800
    /**
801
     * {@inheritdoc}
802
     */
803
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
804
    {
805
        return [
806
            'ALTER TABLE mytable DROP FOREIGN KEY fk_foo',
807
            'DROP INDEX idx_foo ON mytable',
808
            'CREATE INDEX idx_foo_renamed ON mytable (foo)',
809
            'ALTER TABLE mytable ADD CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id)',
810
        ];
811
    }
812
813
    /**
814
     * {@inheritdoc}
815
     */
816
    public function getGeneratesDecimalTypeDeclarationSQL()
817
    {
818
        return [
819
            [[], 'NUMERIC(10, 0)'],
820
            [['unsigned' => true], 'NUMERIC(10, 0) UNSIGNED'],
821
            [['unsigned' => false], 'NUMERIC(10, 0)'],
822
            [['precision' => 5], 'NUMERIC(5, 0)'],
823
            [['scale' => 5], 'NUMERIC(10, 5)'],
824
            [['precision' => 8, 'scale' => 2], 'NUMERIC(8, 2)'],
825
        ];
826
    }
827
828
    /**
829
     * {@inheritdoc}
830
     */
831
    public function getGeneratesFloatDeclarationSQL()
832
    {
833
        return [
834
            [[], 'DOUBLE PRECISION'],
835
            [['unsigned' => true], 'DOUBLE PRECISION UNSIGNED'],
836
            [['unsigned' => false], 'DOUBLE PRECISION'],
837
            [['precision' => 5], 'DOUBLE PRECISION'],
838
            [['scale' => 5], 'DOUBLE PRECISION'],
839
            [['precision' => 8, 'scale' => 2], 'DOUBLE PRECISION'],
840
        ];
841
    }
842
843
    /**
844
     * @group DBAL-2436
845
     */
846
    public function testQuotesTableNameInListTableIndexesSQL()
847
    {
848
        self::assertStringContainsStringIgnoringCase(
849
            "'Foo''Bar\\\\'",
850
            $this->platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db')
851
        );
852
    }
853
854
    /**
855
     * @group DBAL-2436
856
     */
857
    public function testQuotesDatabaseNameInListTableIndexesSQL()
858
    {
859
        self::assertStringContainsStringIgnoringCase(
860
            "'Foo''Bar\\\\'",
861
            $this->platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\")
862
        );
863
    }
864
865
    /**
866
     * @group DBAL-2436
867
     */
868
    public function testQuotesDatabaseNameInListViewsSQL()
869
    {
870
        self::assertStringContainsStringIgnoringCase(
871
            "'Foo''Bar\\\\'",
872
            $this->platform->getListViewsSQL("Foo'Bar\\")
873
        );
874
    }
875
876
    /**
877
     * @group DBAL-2436
878
     */
879
    public function testQuotesTableNameInListTableForeignKeysSQL()
880
    {
881
        self::assertStringContainsStringIgnoringCase(
882
            "'Foo''Bar\\\\'",
883
            $this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
884
        );
885
    }
886
887
    /**
888
     * @group DBAL-2436
889
     */
890
    public function testQuotesDatabaseNameInListTableForeignKeysSQL()
891
    {
892
        self::assertStringContainsStringIgnoringCase(
893
            "'Foo''Bar\\\\'",
894
            $this->platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\")
895
        );
896
    }
897
898
    /**
899
     * @group DBAL-2436
900
     */
901
    public function testQuotesTableNameInListTableColumnsSQL()
902
    {
903
        self::assertStringContainsStringIgnoringCase(
904
            "'Foo''Bar\\\\'",
905
            $this->platform->getListTableColumnsSQL("Foo'Bar\\")
906
        );
907
    }
908
909
    /**
910
     * @group DBAL-2436
911
     */
912
    public function testQuotesDatabaseNameInListTableColumnsSQL()
913
    {
914
        self::assertStringContainsStringIgnoringCase(
915
            "'Foo''Bar\\\\'",
916
            $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\")
917
        );
918
    }
919
920
    public function testListTableForeignKeysSQLEvaluatesDatabase()
921
    {
922
        $sql = $this->platform->getListTableForeignKeysSQL('foo');
923
924
        self::assertStringContainsString('DATABASE()', $sql);
925
926
        $sql = $this->platform->getListTableForeignKeysSQL('foo', 'bar');
927
928
        self::assertStringContainsString('bar', $sql);
929
        self::assertStringNotContainsString('DATABASE()', $sql);
930
    }
931
932
    public function testColumnCharsetDeclarationSQL() : void
933
    {
934
        self::assertSame(
935
            'CHARACTER SET ascii',
936
            $this->platform->getColumnCharsetDeclarationSQL('ascii')
937
        );
938
    }
939
940
    public function testSupportsColumnCollation() : void
941
    {
942
        self::assertTrue($this->platform->supportsColumnCollation());
943
    }
944
945
    public function testColumnCollationDeclarationSQL() : void
946
    {
947
        self::assertSame(
948
            'COLLATE ascii_general_ci',
949
            $this->platform->getColumnCollationDeclarationSQL('ascii_general_ci')
950
        );
951
    }
952
953
    public function testGetCreateTableSQLWithColumnCollation() : void
954
    {
955
        $table = new Table('foo');
956
        $table->addColumn('no_collation', 'string');
957
        $table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'ascii_general_ci');
958
959
        self::assertSame(
960
            ['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'],
961
            $this->platform->getCreateTableSQL($table),
962
            'Column "no_collation" will use the default collation from the table/database and "column_collation" overwrites the collation on this column'
963
        );
964
    }
965
}
966