Failed Conditions
Push — travis-db2 ( e87e37...2c4097 )
by Michael
03:43
created

testColumnCollationDeclarationSQL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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 OFFSET 0', $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
        self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65536)));
523
        self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 16777215)));
524
        self::assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 16777216)));
525
526
        self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
527
        self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
528
        self::assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65535)));
529
        self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65536)));
530
        self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 16777215)));
531
        self::assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 16777216)));
532
    }
533
534
    public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines()
535
    {
536
        $table = new Table("foreign_table");
537
        $table->addColumn('id', 'integer');
538
        $table->addColumn('fk_id', 'integer');
539
        $table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id'));
540
        $table->setPrimaryKey(array('id'));
541
        $table->addOption('engine', 'MyISAM');
542
543
        self::assertSame(
544
            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'),
545
            $this->_platform->getCreateTableSQL(
546
                $table,
547
                AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS
548
            )
549
        );
550
551
        $table = clone $table;
552
        $table->addOption('engine', 'InnoDB');
553
554
        self::assertSame(
555
            array(
556
                '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',
557
                'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)'
558
            ),
559
            $this->_platform->getCreateTableSQL(
560
                $table,
561
                AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS
562
            )
563
        );
564
    }
565
566
    public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines()
567
    {
568
        $table = new Table("foreign_table");
569
        $table->addColumn('id', 'integer');
570
        $table->addColumn('fk_id', 'integer');
571
        $table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id'));
572
        $table->setPrimaryKey(array('id'));
573
        $table->addOption('engine', 'MyISAM');
574
575
        $addedForeignKeys   = array(new ForeignKeyConstraint(array('fk_id'), 'foo', array('id'), 'fk_add'));
576
        $changedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'bar', array('id'), 'fk_change'));
577
        $removedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'baz', array('id'), 'fk_remove'));
578
579
        $tableDiff = new TableDiff('foreign_table');
580
        $tableDiff->fromTable = $table;
581
        $tableDiff->addedForeignKeys = $addedForeignKeys;
582
        $tableDiff->changedForeignKeys = $changedForeignKeys;
583
        $tableDiff->removedForeignKeys = $removedForeignKeys;
584
585
        self::assertEmpty($this->_platform->getAlterTableSQL($tableDiff));
586
587
        $table->addOption('engine', 'InnoDB');
588
589
        $tableDiff = new TableDiff('foreign_table');
590
        $tableDiff->fromTable = $table;
591
        $tableDiff->addedForeignKeys = $addedForeignKeys;
592
        $tableDiff->changedForeignKeys = $changedForeignKeys;
593
        $tableDiff->removedForeignKeys = $removedForeignKeys;
594
595
        self::assertSame(
596
            array(
597
                'ALTER TABLE foreign_table DROP FOREIGN KEY fk_remove',
598
                'ALTER TABLE foreign_table DROP FOREIGN KEY fk_change',
599
                'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)',
600
                'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)',
601
            ),
602
            $this->_platform->getAlterTableSQL($tableDiff)
603
        );
604
    }
605
606
    /**
607
     * @group DBAL-234
608
     */
609
    protected function getAlterTableRenameIndexSQL()
610
    {
611
        return array(
612
            'DROP INDEX idx_foo ON mytable',
613
            'CREATE INDEX idx_bar ON mytable (id)',
614
        );
615
    }
616
617
    /**
618
     * @group DBAL-234
619
     */
620
    protected function getQuotedAlterTableRenameIndexSQL()
621
    {
622
        return array(
623
            'DROP INDEX `create` ON `table`',
624
            'CREATE INDEX `select` ON `table` (id)',
625
            'DROP INDEX `foo` ON `table`',
626
            'CREATE INDEX `bar` ON `table` (id)',
627
        );
628
    }
629
630
    /**
631
     * @group DBAL-807
632
     */
633
    protected function getAlterTableRenameIndexInSchemaSQL()
634
    {
635
        return array(
636
            'DROP INDEX idx_foo ON myschema.mytable',
637
            'CREATE INDEX idx_bar ON myschema.mytable (id)',
638
        );
639
    }
640
641
    /**
642
     * @group DBAL-807
643
     */
644
    protected function getQuotedAlterTableRenameIndexInSchemaSQL()
645
    {
646
        return array(
647
            'DROP INDEX `create` ON `schema`.`table`',
648
            'CREATE INDEX `select` ON `schema`.`table` (id)',
649
            'DROP INDEX `foo` ON `schema`.`table`',
650
            'CREATE INDEX `bar` ON `schema`.`table` (id)',
651
        );
652
    }
653
654
    protected function getQuotesDropForeignKeySQL()
655
    {
656
        return 'ALTER TABLE `table` DROP FOREIGN KEY `select`';
657
    }
658
659
    protected function getQuotesDropConstraintSQL()
660
    {
661
        return 'ALTER TABLE `table` DROP CONSTRAINT `select`';
662
    }
663
664
    public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
665
    {
666
        $table = new Table("text_blob_default_value");
667
        $table->addColumn('def_text', 'text', array('default' => 'def'));
668
        $table->addColumn('def_text_null', 'text', array('notnull' => false, 'default' => 'def'));
669
        $table->addColumn('def_blob', 'blob', array('default' => 'def'));
670
        $table->addColumn('def_blob_null', 'blob', array('notnull' => false, 'default' => 'def'));
671
672
        self::assertSame(
673
            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'),
674
            $this->_platform->getCreateTableSQL($table)
675
        );
676
677
        $diffTable = clone $table;
678
        $diffTable->changeColumn('def_text', array('default' => null));
679
        $diffTable->changeColumn('def_text_null', array('default' => null));
680
        $diffTable->changeColumn('def_blob', array('default' => null));
681
        $diffTable->changeColumn('def_blob_null', array('default' => null));
682
683
        $comparator = new Comparator();
684
685
        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

685
        self::assertEmpty($this->_platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table, $diffTable)));
Loading history...
686
    }
687
688
    /**
689
     * {@inheritdoc}
690
     */
691
    protected function getQuotedAlterTableRenameColumnSQL()
692
    {
693
        return array(
694
            "ALTER TABLE mytable " .
695
            "CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " .
696
            "CHANGE unquoted2 `where` INT NOT NULL COMMENT 'Unquoted 2', " .
697
            "CHANGE unquoted3 `foo` INT NOT NULL COMMENT 'Unquoted 3', " .
698
            "CHANGE `create` reserved_keyword INT NOT NULL COMMENT 'Reserved keyword 1', " .
699
            "CHANGE `table` `from` INT NOT NULL COMMENT 'Reserved keyword 2', " .
700
            "CHANGE `select` `bar` INT NOT NULL COMMENT 'Reserved keyword 3', " .
701
            "CHANGE quoted1 quoted INT NOT NULL COMMENT 'Quoted 1', " .
702
            "CHANGE quoted2 `and` INT NOT NULL COMMENT 'Quoted 2', " .
703
            "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'"
704
        );
705
    }
706
707
    /**
708
     * {@inheritdoc}
709
     */
710
    protected function getQuotedAlterTableChangeColumnLengthSQL()
711
    {
712
        return array(
713
            "ALTER TABLE mytable " .
714
            "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " .
715
            "CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " .
716
            "CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " .
717
            "CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " .
718
            "CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " .
719
            "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'"
720
        );
721
    }
722
723
    /**
724
     * @group DBAL-423
725
     */
726
    public function testReturnsGuidTypeDeclarationSQL()
727
    {
728
        self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
729
    }
730
731
    /**
732
     * {@inheritdoc}
733
     */
734
    public function getAlterTableRenameColumnSQL()
735
    {
736
        return array(
737
            "ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'",
738
        );
739
    }
740
741
    /**
742
     * {@inheritdoc}
743
     */
744
    protected function getQuotesTableIdentifiersInAlterTableSQL()
745
    {
746
        return array(
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 array(
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 array(
798
            'ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL',
799
        );
800
    }
801
802
    /**
803
     * {@inheritdoc}
804
     */
805
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
806
    {
807
        return array(
808
            'ALTER TABLE mytable DROP FOREIGN KEY fk_foo',
809
            'DROP INDEX idx_foo ON mytable',
810
            'CREATE INDEX idx_foo_renamed ON mytable (foo)',
811
            'ALTER TABLE mytable ADD CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id)',
812
        );
813
    }
814
815
    /**
816
     * {@inheritdoc}
817
     */
818
    public function getGeneratesDecimalTypeDeclarationSQL()
819
    {
820
        return array(
821
            array(array(), 'NUMERIC(10, 0)'),
822
            array(array('unsigned' => true), 'NUMERIC(10, 0) UNSIGNED'),
823
            array(array('unsigned' => false), 'NUMERIC(10, 0)'),
824
            array(array('precision' => 5), 'NUMERIC(5, 0)'),
825
            array(array('scale' => 5), 'NUMERIC(10, 5)'),
826
            array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'),
827
        );
828
    }
829
830
    /**
831
     * {@inheritdoc}
832
     */
833
    public function getGeneratesFloatDeclarationSQL()
834
    {
835
        return array(
836
            array(array(), 'DOUBLE PRECISION'),
837
            array(array('unsigned' => true), 'DOUBLE PRECISION UNSIGNED'),
838
            array(array('unsigned' => false), 'DOUBLE PRECISION'),
839
            array(array('precision' => 5), 'DOUBLE PRECISION'),
840
            array(array('scale' => 5), 'DOUBLE PRECISION'),
841
            array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'),
842
        );
843
    }
844
845
    /**
846
     * @group DBAL-2436
847
     */
848
    public function testQuotesTableNameInListTableIndexesSQL()
849
    {
850
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db'), '', true);
851
    }
852
853
    /**
854
     * @group DBAL-2436
855
     */
856
    public function testQuotesDatabaseNameInListTableIndexesSQL()
857
    {
858
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\"), '', true);
859
    }
860
861
    /**
862
     * @group DBAL-2436
863
     */
864
    public function testQuotesDatabaseNameInListViewsSQL()
865
    {
866
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListViewsSQL("Foo'Bar\\"), '', true);
867
    }
868
869
    /**
870
     * @group DBAL-2436
871
     */
872
    public function testQuotesTableNameInListTableForeignKeysSQL()
873
    {
874
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
875
    }
876
877
    /**
878
     * @group DBAL-2436
879
     */
880
    public function testQuotesDatabaseNameInListTableForeignKeysSQL()
881
    {
882
        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

882
        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...
883
    }
884
885
    /**
886
     * @group DBAL-2436
887
     */
888
    public function testQuotesTableNameInListTableColumnsSQL()
889
    {
890
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
891
    }
892
893
    /**
894
     * @group DBAL-2436
895
     */
896
    public function testQuotesDatabaseNameInListTableColumnsSQL()
897
    {
898
        self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true);
899
    }
900
901
    public function testListTableForeignKeysSQLEvaluatesDatabase()
902
    {
903
        $sql = $this->_platform->getListTableForeignKeysSQL('foo');
904
905
        self::assertContains('DATABASE()', $sql);
906
907
        $sql = $this->_platform->getListTableForeignKeysSQL('foo', 'bar');
908
909
        self::assertContains('bar', $sql);
910
        self::assertNotContains('DATABASE()', $sql);
911
    }
912
913
    public function testSupportsColumnCollation() : void
914
    {
915
        self::assertTrue($this->_platform->supportsColumnCollation());
916
    }
917
918
    public function testColumnCollationDeclarationSQL() : void
919
    {
920
        self::assertSame(
921
            'COLLATE ascii_general_ci',
922
            $this->_platform->getColumnCollationDeclarationSQL('ascii_general_ci')
923
        );
924
    }
925
926
    public function testGetCreateTableSQLWithColumnCollation() : void
927
    {
928
        $table = new Table('foo');
929
        $table->addColumn('no_collation', 'string');
930
        $table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'ascii_general_ci');
931
932
        self::assertSame(
933
            ['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'],
934
            $this->_platform->getCreateTableSQL($table),
935
            'Column "no_collation" will use the default collation from the table/database and "column_collation" overwrites the collation on this column'
936
        );
937
    }
938
}
939