Completed
Pull Request — master (#3499)
by David
62:35
created

PostgreSqlSchemaManagerTest::testCommentInTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Functional\Schema;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
7
use Doctrine\DBAL\Schema;
8
use Doctrine\DBAL\Schema\Comparator;
9
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
10
use Doctrine\DBAL\Schema\Table;
11
use Doctrine\DBAL\Schema\TableDiff;
12
use Doctrine\DBAL\Types\BlobType;
13
use Doctrine\DBAL\Types\DecimalType;
14
use Doctrine\DBAL\Types\Type;
15
use function array_map;
16
use function array_pop;
17
use function count;
18
use function strtolower;
19
20
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
21
{
22
    protected function tearDown() : void
23
    {
24
        parent::tearDown();
25
26
        if (! $this->connection) {
27
            return;
28
        }
29
30
        $this->connection->getConfiguration()->setFilterSchemaAssetsExpression(null);
1 ignored issue
show
Deprecated Code introduced by
The function Doctrine\DBAL\Configurat...chemaAssetsExpression() has been deprecated: Use Configuration::setSchemaAssetsFilter() instead ( Ignorable by Annotation )

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

30
        /** @scrutinizer ignore-deprecated */ $this->connection->getConfiguration()->setFilterSchemaAssetsExpression(null);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
31
    }
32
33
    /**
34
     * @group DBAL-177
35
     */
36
    public function testGetSearchPath()
37
    {
38
        $params = $this->connection->getParams();
39
40
        $paths = $this->schemaManager->getSchemaSearchPaths();
41
        self::assertEquals([$params['user'], 'public'], $paths);
42
    }
43
44
    /**
45
     * @group DBAL-244
46
     */
47
    public function testGetSchemaNames()
48
    {
49
        $names = $this->schemaManager->getSchemaNames();
0 ignored issues
show
Bug introduced by
The method getSchemaNames() does not exist on Doctrine\DBAL\Schema\AbstractSchemaManager. It seems like you code against a sub-type of Doctrine\DBAL\Schema\AbstractSchemaManager such as Doctrine\DBAL\Schema\PostgreSqlSchemaManager. ( Ignorable by Annotation )

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

49
        /** @scrutinizer ignore-call */ 
50
        $names = $this->schemaManager->getSchemaNames();
Loading history...
50
51
        self::assertIsArray($names);
52
        self::assertNotEmpty($names);
53
        self::assertContains('public', $names, 'The public schema should be found.');
54
    }
55
56
    /**
57
     * @group DBAL-21
58
     */
59
    public function testSupportDomainTypeFallback()
60
    {
61
        $createDomainTypeSQL = 'CREATE DOMAIN MyMoney AS DECIMAL(18,2)';
62
        $this->connection->exec($createDomainTypeSQL);
63
64
        $createTableSQL = 'CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)';
65
        $this->connection->exec($createTableSQL);
66
67
        $table = $this->connection->getSchemaManager()->listTableDetails('domain_type_test');
68
        self::assertInstanceOf(DecimalType::class, $table->getColumn('value')->getType());
69
70
        Type::addType('MyMoney', MoneyType::class);
71
        $this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney', 'MyMoney');
72
73
        $table = $this->connection->getSchemaManager()->listTableDetails('domain_type_test');
74
        self::assertInstanceOf(MoneyType::class, $table->getColumn('value')->getType());
75
    }
76
77
    /**
78
     * @group DBAL-37
79
     */
80
    public function testDetectsAutoIncrement()
81
    {
82
        $autoincTable = new Table('autoinc_table');
83
        $column       = $autoincTable->addColumn('id', 'integer');
84
        $column->setAutoincrement(true);
85
        $this->schemaManager->createTable($autoincTable);
86
        $autoincTable = $this->schemaManager->listTableDetails('autoinc_table');
87
88
        self::assertTrue($autoincTable->getColumn('id')->getAutoincrement());
89
    }
90
91
    /**
92
     * @group DBAL-37
93
     */
94
    public function testAlterTableAutoIncrementAdd()
95
    {
96
        $tableFrom = new Table('autoinc_table_add');
97
        $column    = $tableFrom->addColumn('id', 'integer');
0 ignored issues
show
Unused Code introduced by
The assignment to $column is dead and can be removed.
Loading history...
98
        $this->schemaManager->createTable($tableFrom);
99
        $tableFrom = $this->schemaManager->listTableDetails('autoinc_table_add');
100
        self::assertFalse($tableFrom->getColumn('id')->getAutoincrement());
101
102
        $tableTo = new Table('autoinc_table_add');
103
        $column  = $tableTo->addColumn('id', 'integer');
104
        $column->setAutoincrement(true);
105
106
        $c    = new Comparator();
107
        $diff = $c->diffTable($tableFrom, $tableTo);
108
        $sql  = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff);
109
        self::assertEquals([
110
            'CREATE SEQUENCE autoinc_table_add_id_seq',
111
            "SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))",
112
            "ALTER TABLE autoinc_table_add ALTER id SET DEFAULT nextval('autoinc_table_add_id_seq')",
113
        ], $sql);
114
115
        $this->schemaManager->alterTable($diff);
116
        $tableFinal = $this->schemaManager->listTableDetails('autoinc_table_add');
117
        self::assertTrue($tableFinal->getColumn('id')->getAutoincrement());
118
    }
119
120
    /**
121
     * @group DBAL-37
122
     */
123
    public function testAlterTableAutoIncrementDrop()
124
    {
125
        $tableFrom = new Table('autoinc_table_drop');
126
        $column    = $tableFrom->addColumn('id', 'integer');
127
        $column->setAutoincrement(true);
128
        $this->schemaManager->createTable($tableFrom);
129
        $tableFrom = $this->schemaManager->listTableDetails('autoinc_table_drop');
130
        self::assertTrue($tableFrom->getColumn('id')->getAutoincrement());
131
132
        $tableTo = new Table('autoinc_table_drop');
133
        $column  = $tableTo->addColumn('id', 'integer');
0 ignored issues
show
Unused Code introduced by
The assignment to $column is dead and can be removed.
Loading history...
134
135
        $c    = new Comparator();
136
        $diff = $c->diffTable($tableFrom, $tableTo);
137
        self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison');
138
        self::assertEquals(['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff));
139
140
        $this->schemaManager->alterTable($diff);
141
        $tableFinal = $this->schemaManager->listTableDetails('autoinc_table_drop');
142
        self::assertFalse($tableFinal->getColumn('id')->getAutoincrement());
143
    }
144
145
    /**
146
     * @group DBAL-75
147
     */
148
    public function testTableWithSchema()
149
    {
150
        $this->connection->exec('CREATE SCHEMA nested');
151
152
        $nestedRelatedTable = new Table('nested.schemarelated');
153
        $column             = $nestedRelatedTable->addColumn('id', 'integer');
154
        $column->setAutoincrement(true);
155
        $nestedRelatedTable->setPrimaryKey(['id']);
156
157
        $nestedSchemaTable = new Table('nested.schematable');
158
        $column            = $nestedSchemaTable->addColumn('id', 'integer');
159
        $column->setAutoincrement(true);
160
        $nestedSchemaTable->setPrimaryKey(['id']);
161
        $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']);
1 ignored issue
show
Deprecated Code introduced by
The function Doctrine\DBAL\Schema\Tab...dForeignKeyConstraint() has been deprecated: Use {@link addForeignKeyConstraint} ( Ignorable by Annotation )

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

161
        /** @scrutinizer ignore-deprecated */ $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
162
163
        $this->schemaManager->createTable($nestedRelatedTable);
164
        $this->schemaManager->createTable($nestedSchemaTable);
165
166
        $tables = $this->schemaManager->listTableNames();
167
        self::assertContains('nested.schematable', $tables, 'The table should be detected with its non-public schema.');
168
169
        $nestedSchemaTable = $this->schemaManager->listTableDetails('nested.schematable');
170
        self::assertTrue($nestedSchemaTable->hasColumn('id'));
171
        self::assertEquals(['id'], $nestedSchemaTable->getPrimaryKey()->getColumns());
172
173
        $relatedFks = $nestedSchemaTable->getForeignKeys();
174
        self::assertCount(1, $relatedFks);
175
        $relatedFk = array_pop($relatedFks);
176
        self::assertEquals('nested.schemarelated', $relatedFk->getForeignTableName());
177
    }
178
179
    /**
180
     * @group DBAL-91
181
     * @group DBAL-88
182
     */
183
    public function testReturnQuotedAssets()
184
    {
185
        $sql = 'create table dbal91_something ( id integer  CONSTRAINT id_something PRIMARY KEY NOT NULL  ,"table"   integer );';
186
        $this->connection->exec($sql);
187
188
        $sql = 'ALTER TABLE dbal91_something ADD CONSTRAINT something_input FOREIGN KEY( "table" ) REFERENCES dbal91_something ON UPDATE CASCADE;';
189
        $this->connection->exec($sql);
190
191
        $table = $this->schemaManager->listTableDetails('dbal91_something');
192
193
        self::assertEquals(
194
            [
195
                'CREATE TABLE dbal91_something (id INT NOT NULL, "table" INT DEFAULT NULL, PRIMARY KEY(id))',
196
                'CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something ("table")',
197
            ],
198
            $this->connection->getDatabasePlatform()->getCreateTableSQL($table)
199
        );
200
    }
201
202
    /**
203
     * @group DBAL-204
204
     */
205
    public function testFilterSchemaExpression()
206
    {
207
        $testTable = new Table('dbal204_test_prefix');
208
        $column    = $testTable->addColumn('id', 'integer');
0 ignored issues
show
Unused Code introduced by
The assignment to $column is dead and can be removed.
Loading history...
209
        $this->schemaManager->createTable($testTable);
210
        $testTable = new Table('dbal204_without_prefix');
211
        $column    = $testTable->addColumn('id', 'integer');
212
        $this->schemaManager->createTable($testTable);
213
214
        $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#');
1 ignored issue
show
Deprecated Code introduced by
The function Doctrine\DBAL\Configurat...chemaAssetsExpression() has been deprecated: Use Configuration::setSchemaAssetsFilter() instead ( Ignorable by Annotation )

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

214
        /** @scrutinizer ignore-deprecated */ $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
215
        $names = $this->schemaManager->listTableNames();
216
        self::assertCount(2, $names);
217
218
        $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_test#');
219
        $names = $this->schemaManager->listTableNames();
220
        self::assertCount(1, $names);
221
    }
222
223
    public function testListForeignKeys()
224
    {
225
        if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
226
            $this->markTestSkipped('Does not support foreign key constraints.');
227
        }
228
229
        $fkOptions   = ['SET NULL', 'SET DEFAULT', 'NO ACTION','CASCADE', 'RESTRICT'];
230
        $foreignKeys = [];
231
        $fkTable     = $this->getTestTable('test_create_fk1');
232
        for ($i = 0; $i < count($fkOptions); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
233
            $fkTable->addColumn('foreign_key_test' . $i, 'integer');
234
            $foreignKeys[] = new ForeignKeyConstraint(
235
                ['foreign_key_test' . $i],
236
                'test_create_fk2',
237
                ['id'],
238
                'foreign_key_test' . $i . '_fk',
239
                ['onDelete' => $fkOptions[$i]]
240
            );
241
        }
242
        $this->schemaManager->dropAndCreateTable($fkTable);
243
        $this->createTestTable('test_create_fk2');
244
245
        foreach ($foreignKeys as $foreignKey) {
246
            $this->schemaManager->createForeignKey($foreignKey, 'test_create_fk1');
247
        }
248
        $fkeys = $this->schemaManager->listTableForeignKeys('test_create_fk1');
249
        self::assertEquals(count($foreignKeys), count($fkeys), "Table 'test_create_fk1' has to have " . count($foreignKeys) . ' foreign keys.');
250
        for ($i = 0; $i < count($fkeys); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
251
            self::assertEquals(['foreign_key_test' . $i], array_map('strtolower', $fkeys[$i]->getLocalColumns()));
252
            self::assertEquals(['id'], array_map('strtolower', $fkeys[$i]->getForeignColumns()));
253
            self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName()));
254
            if ($foreignKeys[$i]->getOption('onDelete') === 'NO ACTION') {
255
                self::assertFalse($fkeys[$i]->hasOption('onDelete'), 'Unexpected option: ' . $fkeys[$i]->getOption('onDelete'));
256
            } else {
257
                self::assertEquals($foreignKeys[$i]->getOption('onDelete'), $fkeys[$i]->getOption('onDelete'));
258
            }
259
        }
260
    }
261
262
    /**
263
     * @group DBAL-511
264
     */
265
    public function testDefaultValueCharacterVarying()
266
    {
267
        $testTable = new Table('dbal511_default');
268
        $testTable->addColumn('id', 'integer');
269
        $testTable->addColumn('def', 'string', ['default' => 'foo']);
270
        $testTable->setPrimaryKey(['id']);
271
272
        $this->schemaManager->createTable($testTable);
273
274
        $databaseTable = $this->schemaManager->listTableDetails($testTable->getName());
275
276
        self::assertEquals('foo', $databaseTable->getColumn('def')->getDefault());
277
    }
278
279
    /**
280
     * @group DDC-2843
281
     */
282
    public function testBooleanDefault()
283
    {
284
        $table = new Table('ddc2843_bools');
285
        $table->addColumn('id', 'integer');
286
        $table->addColumn('checked', 'boolean', ['default' => false]);
287
288
        $this->schemaManager->createTable($table);
289
290
        $databaseTable = $this->schemaManager->listTableDetails($table->getName());
291
292
        $c    = new Comparator();
293
        $diff = $c->diffTable($table, $databaseTable);
294
295
        self::assertFalse($diff);
296
    }
297
298
    public function testListTableWithBinary()
299
    {
300
        $tableName = 'test_binary_table';
301
302
        $table = new Table($tableName);
303
        $table->addColumn('id', 'integer');
304
        $table->addColumn('column_varbinary', 'binary', []);
305
        $table->addColumn('column_binary', 'binary', ['fixed' => true]);
306
        $table->setPrimaryKey(['id']);
307
308
        $this->schemaManager->createTable($table);
309
310
        $table = $this->schemaManager->listTableDetails($tableName);
311
312
        self::assertInstanceOf(BlobType::class, $table->getColumn('column_varbinary')->getType());
313
        self::assertFalse($table->getColumn('column_varbinary')->getFixed());
314
315
        self::assertInstanceOf(BlobType::class, $table->getColumn('column_binary')->getType());
316
        self::assertFalse($table->getColumn('column_binary')->getFixed());
317
    }
318
319
    public function testListQuotedTable()
320
    {
321
        $offlineTable = new Schema\Table('user');
322
        $offlineTable->addColumn('id', 'integer');
323
        $offlineTable->addColumn('username', 'string');
324
        $offlineTable->addColumn('fk', 'integer');
325
        $offlineTable->setPrimaryKey(['id']);
326
        $offlineTable->addForeignKeyConstraint($offlineTable, ['fk'], ['id']);
327
328
        $this->schemaManager->dropAndCreateTable($offlineTable);
329
330
        $onlineTable = $this->schemaManager->listTableDetails('"user"');
331
332
        $comparator = new Schema\Comparator();
333
334
        self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
335
    }
336
337
    public function testListTablesExcludesViews()
338
    {
339
        $this->createTestTable('list_tables_excludes_views');
340
341
        $name = 'list_tables_excludes_views_test_view';
342
        $sql  = 'SELECT * from list_tables_excludes_views';
343
344
        $view = new Schema\View($name, $sql);
345
346
        $this->schemaManager->dropAndCreateView($view);
347
348
        $tables = $this->schemaManager->listTables();
349
350
        $foundTable = false;
351
        foreach ($tables as $table) {
352
            self::assertInstanceOf(Table::class, $table, 'No Table instance was found in tables array.');
353
            if (strtolower($table->getName()) !== 'list_tables_excludes_views_test_view') {
354
                continue;
355
            }
356
357
            $foundTable = true;
358
        }
359
360
        self::assertFalse($foundTable, 'View "list_tables_excludes_views_test_view" must not be found in table list');
361
    }
362
363
    /**
364
     * @group DBAL-1033
365
     */
366
    public function testPartialIndexes()
367
    {
368
        $offlineTable = new Schema\Table('person');
369
        $offlineTable->addColumn('id', 'integer');
370
        $offlineTable->addColumn('name', 'string');
371
        $offlineTable->addColumn('email', 'string');
372
        $offlineTable->addUniqueIndex(['id', 'name'], 'simple_partial_index', ['where' => '(id IS NULL)']);
373
374
        $this->schemaManager->dropAndCreateTable($offlineTable);
375
376
        $onlineTable = $this->schemaManager->listTableDetails('person');
377
378
        $comparator = new Schema\Comparator();
379
380
        self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
381
        self::assertTrue($onlineTable->hasIndex('simple_partial_index'));
382
        self::assertTrue($onlineTable->getIndex('simple_partial_index')->hasOption('where'));
383
        self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where'));
384
    }
385
386
    /**
387
     * @dataProvider jsonbColumnTypeProvider
388
     */
389
    public function testJsonbColumn(string $type) : void
390
    {
391
        if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) {
392
            $this->markTestSkipped('Requires PostgresSQL 9.4+');
393
394
            return;
395
        }
396
397
        $table = new Schema\Table('test_jsonb');
398
        $table->addColumn('foo', $type)->setPlatformOption('jsonb', true);
399
        $this->schemaManager->dropAndCreateTable($table);
400
401
        $columns = $this->schemaManager->listTableColumns('test_jsonb');
402
403
        self::assertSame($type, $columns['foo']->getType()->getName());
404
        self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb'));
405
    }
406
407
    /**
408
     * @return mixed[][]
409
     */
410
    public function jsonbColumnTypeProvider() : array
411
    {
412
        return [
413
            [Type::JSON],
414
            [Type::JSON_ARRAY],
415
        ];
416
    }
417
418
    /**
419
     * @group DBAL-2427
420
     */
421
    public function testListNegativeColumnDefaultValue()
422
    {
423
        $table = new Schema\Table('test_default_negative');
424
        $table->addColumn('col_smallint', 'smallint', ['default' => -1]);
425
        $table->addColumn('col_integer', 'integer', ['default' => -1]);
426
        $table->addColumn('col_bigint', 'bigint', ['default' => -1]);
427
        $table->addColumn('col_float', 'float', ['default' => -1.1]);
428
        $table->addColumn('col_decimal', 'decimal', ['default' => -1.1]);
429
        $table->addColumn('col_string', 'string', ['default' => '(-1)']);
430
431
        $this->schemaManager->dropAndCreateTable($table);
432
433
        $columns = $this->schemaManager->listTableColumns('test_default_negative');
434
435
        self::assertEquals(-1, $columns['col_smallint']->getDefault());
436
        self::assertEquals(-1, $columns['col_integer']->getDefault());
437
        self::assertEquals(-1, $columns['col_bigint']->getDefault());
438
        self::assertEquals(-1.1, $columns['col_float']->getDefault());
439
        self::assertEquals(-1.1, $columns['col_decimal']->getDefault());
440
        self::assertEquals('(-1)', $columns['col_string']->getDefault());
441
    }
442
443
    /**
444
     * @return mixed[][]
445
     */
446
    public static function serialTypes() : array
447
    {
448
        return [
449
            ['integer'],
450
            ['bigint'],
451
        ];
452
    }
453
454
    /**
455
     * @dataProvider serialTypes
456
     * @group 2906
457
     */
458
    public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValue(string $type) : void
459
    {
460
        $tableName = 'test_serial_type_' . $type;
461
462
        $table = new Schema\Table($tableName);
463
        $table->addColumn('id', $type, ['autoincrement' => true, 'notnull' => false]);
464
465
        $this->schemaManager->dropAndCreateTable($table);
466
467
        $columns = $this->schemaManager->listTableColumns($tableName);
468
469
        self::assertNull($columns['id']->getDefault());
470
    }
471
472
    /**
473
     * @dataProvider serialTypes
474
     * @group 2906
475
     */
476
    public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValueEvenWhenDefaultIsSet(string $type) : void
477
    {
478
        $tableName = 'test_serial_type_with_default_' . $type;
479
480
        $table = new Schema\Table($tableName);
481
        $table->addColumn('id', $type, ['autoincrement' => true, 'notnull' => false, 'default' => 1]);
482
483
        $this->schemaManager->dropAndCreateTable($table);
484
485
        $columns = $this->schemaManager->listTableColumns($tableName);
486
487
        self::assertNull($columns['id']->getDefault());
488
    }
489
490
    /**
491
     * @group 2916
492
     * @dataProvider autoIncrementTypeMigrations
493
     */
494
    public function testAlterTableAutoIncrementIntToBigInt(string $from, string $to, string $expected) : void
495
    {
496
        $tableFrom = new Table('autoinc_type_modification');
497
        $column    = $tableFrom->addColumn('id', $from);
498
        $column->setAutoincrement(true);
499
        $this->schemaManager->dropAndCreateTable($tableFrom);
500
        $tableFrom = $this->schemaManager->listTableDetails('autoinc_type_modification');
501
        self::assertTrue($tableFrom->getColumn('id')->getAutoincrement());
502
503
        $tableTo = new Table('autoinc_type_modification');
504
        $column  = $tableTo->addColumn('id', $to);
505
        $column->setAutoincrement(true);
506
507
        $c    = new Comparator();
508
        $diff = $c->diffTable($tableFrom, $tableTo);
509
        self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison');
510
        self::assertSame(['ALTER TABLE autoinc_type_modification ALTER id TYPE ' . $expected], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff));
511
512
        $this->schemaManager->alterTable($diff);
513
        $tableFinal = $this->schemaManager->listTableDetails('autoinc_type_modification');
514
        self::assertTrue($tableFinal->getColumn('id')->getAutoincrement());
515
    }
516
517
    public function testCommentInTable() : void
518
    {
519
        $table = new Table('table_with_comment');
520
        $table->addColumn('id', 'integer');
521
        $table->addOption('comment', 'Foo');
522
        $this->schemaManager->dropAndCreateTable($table);
523
524
        $table = $this->schemaManager->listTableDetails('table_with_comment');
525
        self::assertSame('Foo', $table->getOption('comment'));
526
    }
527
528
    /**
529
     * @return mixed[][]
530
     */
531
    public function autoIncrementTypeMigrations() : array
532
    {
533
        return [
534
            'int->bigint' => ['integer', 'bigint', 'BIGINT'],
535
            'bigint->int' => ['bigint', 'integer', 'INT'],
536
        ];
537
    }
538
}
539
540
class MoneyType extends Type
541
{
542
    public function getName()
543
    {
544
        return 'MyMoney';
545
    }
546
547
    /**
548
     * {@inheritDoc}
549
     */
550
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
551
    {
552
        return 'MyMoney';
553
    }
554
}
555