Completed
Pull Request — master (#3711)
by
unknown
15:37
created

testQuotingMixedCaseAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
rs 10
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 Doctrine\DBAL\Types\Types;
16
use function array_map;
17
use function array_pop;
18
use function count;
19
use function current;
20
use function strtolower;
21
22
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
23
{
24
    protected function tearDown() : void
25
    {
26
        parent::tearDown();
27
28
        if (! $this->connection) {
29
            return;
30
        }
31
32
        $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

32
        /** @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...
33
    }
34
35
    /**
36
     * @group DBAL-177
37
     */
38
    public function testGetSearchPath() : void
39
    {
40
        $params = $this->connection->getParams();
41
42
        $paths = $this->schemaManager->getSchemaSearchPaths();
43
        self::assertEquals([$params['user'], 'public'], $paths);
44
    }
45
46
    /**
47
     * @group DBAL-244
48
     */
49
    public function testGetSchemaNames() : void
50
    {
51
        $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

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

163
        /** @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...
164
165
        $this->schemaManager->createTable($nestedRelatedTable);
166
        $this->schemaManager->createTable($nestedSchemaTable);
167
168
        $tables = $this->schemaManager->listTableNames();
169
        self::assertContains('nested.schematable', $tables, 'The table should be detected with its non-public schema.');
170
171
        $nestedSchemaTable = $this->schemaManager->listTableDetails('nested.schematable');
172
        self::assertTrue($nestedSchemaTable->hasColumn('id'));
173
        self::assertEquals(['id'], $nestedSchemaTable->getPrimaryKey()->getColumns());
174
175
        $relatedFks = $nestedSchemaTable->getForeignKeys();
176
        self::assertCount(1, $relatedFks);
177
        $relatedFk = array_pop($relatedFks);
178
        self::assertEquals('nested.schemarelated', $relatedFk->getForeignTableName());
179
    }
180
181
    /**
182
     * @group DBAL-91
183
     * @group DBAL-88
184
     */
185
    public function testReturnQuotedAssets() : void
186
    {
187
        $sql = 'create table dbal91_something ( id integer  CONSTRAINT id_something PRIMARY KEY NOT NULL  ,"table"   integer );';
188
        $this->connection->exec($sql);
189
190
        $sql = 'ALTER TABLE dbal91_something ADD CONSTRAINT something_input FOREIGN KEY( "table" ) REFERENCES dbal91_something ON UPDATE CASCADE;';
191
        $this->connection->exec($sql);
192
193
        $table = $this->schemaManager->listTableDetails('dbal91_something');
194
195
        self::assertEquals(
196
            [
197
                'CREATE TABLE dbal91_something (id INT NOT NULL, "table" INT DEFAULT NULL, PRIMARY KEY(id))',
198
                'CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something ("table")',
199
            ],
200
            $this->connection->getDatabasePlatform()->getCreateTableSQL($table)
201
        );
202
    }
203
204
    /**
205
     * @group DBAL-204
206
     */
207
    public function testFilterSchemaExpression() : void
208
    {
209
        $testTable = new Table('dbal204_test_prefix');
210
        $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...
211
        $this->schemaManager->createTable($testTable);
212
        $testTable = new Table('dbal204_without_prefix');
213
        $column    = $testTable->addColumn('id', 'integer');
214
        $this->schemaManager->createTable($testTable);
215
216
        $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

216
        /** @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...
217
        $names = $this->schemaManager->listTableNames();
218
        self::assertCount(2, $names);
219
220
        $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_test#');
221
        $names = $this->schemaManager->listTableNames();
222
        self::assertCount(1, $names);
223
    }
224
225
    public function testListForeignKeys() : void
226
    {
227
        if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
228
            $this->markTestSkipped('Does not support foreign key constraints.');
229
        }
230
231
        $fkOptions   = ['SET NULL', 'SET DEFAULT', 'NO ACTION','CASCADE', 'RESTRICT'];
232
        $foreignKeys = [];
233
        $fkTable     = $this->getTestTable('test_create_fk1');
234
        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...
235
            $fkTable->addColumn('foreign_key_test' . $i, 'integer');
236
            $foreignKeys[] = new ForeignKeyConstraint(
237
                ['foreign_key_test' . $i],
238
                'test_create_fk2',
239
                ['id'],
240
                'foreign_key_test' . $i . '_fk',
241
                ['onDelete' => $fkOptions[$i]]
242
            );
243
        }
244
        $this->schemaManager->dropAndCreateTable($fkTable);
245
        $this->createTestTable('test_create_fk2');
246
247
        foreach ($foreignKeys as $foreignKey) {
248
            $this->schemaManager->createForeignKey($foreignKey, 'test_create_fk1');
249
        }
250
        $fkeys = $this->schemaManager->listTableForeignKeys('test_create_fk1');
251
        self::assertEquals(count($foreignKeys), count($fkeys), "Table 'test_create_fk1' has to have " . count($foreignKeys) . ' foreign keys.');
252
        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...
253
            self::assertEquals(['foreign_key_test' . $i], array_map('strtolower', $fkeys[$i]->getLocalColumns()));
254
            self::assertEquals(['id'], array_map('strtolower', $fkeys[$i]->getForeignColumns()));
255
            self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName()));
256
            if ($foreignKeys[$i]->getOption('onDelete') === 'NO ACTION') {
257
                self::assertFalse($fkeys[$i]->hasOption('onDelete'), 'Unexpected option: ' . $fkeys[$i]->getOption('onDelete'));
258
            } else {
259
                self::assertEquals($foreignKeys[$i]->getOption('onDelete'), $fkeys[$i]->getOption('onDelete'));
260
            }
261
        }
262
    }
263
264
    /**
265
     * @group DBAL-511
266
     */
267
    public function testDefaultValueCharacterVarying() : void
268
    {
269
        $testTable = new Table('dbal511_default');
270
        $testTable->addColumn('id', 'integer');
271
        $testTable->addColumn('def', 'string', ['default' => 'foo']);
272
        $testTable->setPrimaryKey(['id']);
273
274
        $this->schemaManager->createTable($testTable);
275
276
        $databaseTable = $this->schemaManager->listTableDetails($testTable->getName());
277
278
        self::assertEquals('foo', $databaseTable->getColumn('def')->getDefault());
279
    }
280
281
    /**
282
     * @group DDC-2843
283
     */
284
    public function testBooleanDefault() : void
285
    {
286
        $table = new Table('ddc2843_bools');
287
        $table->addColumn('id', 'integer');
288
        $table->addColumn('checked', 'boolean', ['default' => false]);
289
290
        $this->schemaManager->createTable($table);
291
292
        $databaseTable = $this->schemaManager->listTableDetails($table->getName());
293
294
        $c    = new Comparator();
295
        $diff = $c->diffTable($table, $databaseTable);
296
297
        self::assertFalse($diff);
298
    }
299
300
    public function testListTableWithBinary() : void
301
    {
302
        $tableName = 'test_binary_table';
303
304
        $table = new Table($tableName);
305
        $table->addColumn('id', 'integer');
306
        $table->addColumn('column_varbinary', 'binary', []);
307
        $table->addColumn('column_binary', 'binary', ['fixed' => true]);
308
        $table->setPrimaryKey(['id']);
309
310
        $this->schemaManager->createTable($table);
311
312
        $table = $this->schemaManager->listTableDetails($tableName);
313
314
        self::assertInstanceOf(BlobType::class, $table->getColumn('column_varbinary')->getType());
315
        self::assertFalse($table->getColumn('column_varbinary')->getFixed());
316
317
        self::assertInstanceOf(BlobType::class, $table->getColumn('column_binary')->getType());
318
        self::assertFalse($table->getColumn('column_binary')->getFixed());
319
    }
320
321
    public function testListQuotedTable() : void
322
    {
323
        $offlineTable = new Schema\Table('user');
324
        $offlineTable->addColumn('id', 'integer');
325
        $offlineTable->addColumn('username', 'string');
326
        $offlineTable->addColumn('fk', 'integer');
327
        $offlineTable->setPrimaryKey(['id']);
328
        $offlineTable->addForeignKeyConstraint($offlineTable, ['fk'], ['id']);
329
330
        $this->schemaManager->dropAndCreateTable($offlineTable);
331
332
        $onlineTable = $this->schemaManager->listTableDetails('"user"');
333
334
        $comparator = new Schema\Comparator();
335
336
        self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
337
    }
338
339
    public function testListTablesExcludesViews() : void
340
    {
341
        $this->createTestTable('list_tables_excludes_views');
342
343
        $name = 'list_tables_excludes_views_test_view';
344
        $sql  = 'SELECT * from list_tables_excludes_views';
345
346
        $view = new Schema\View($name, $sql);
347
348
        $this->schemaManager->dropAndCreateView($view);
349
350
        $tables = $this->schemaManager->listTables();
351
352
        $foundTable = false;
353
        foreach ($tables as $table) {
354
            self::assertInstanceOf(Table::class, $table, 'No Table instance was found in tables array.');
355
            if (strtolower($table->getName()) !== 'list_tables_excludes_views_test_view') {
356
                continue;
357
            }
358
359
            $foundTable = true;
360
        }
361
362
        self::assertFalse($foundTable, 'View "list_tables_excludes_views_test_view" must not be found in table list');
363
    }
364
365
    /**
366
     * @group DBAL-1033
367
     */
368
    public function testPartialIndexes() : void
369
    {
370
        $offlineTable = new Schema\Table('person');
371
        $offlineTable->addColumn('id', 'integer');
372
        $offlineTable->addColumn('name', 'string');
373
        $offlineTable->addColumn('email', 'string');
374
        $offlineTable->addUniqueIndex(['id', 'name'], 'simple_partial_index', ['where' => '(id IS NULL)']);
375
376
        $this->schemaManager->dropAndCreateTable($offlineTable);
377
378
        $onlineTable = $this->schemaManager->listTableDetails('person');
379
380
        $comparator = new Schema\Comparator();
381
382
        self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
383
        self::assertTrue($onlineTable->hasIndex('simple_partial_index'));
384
        self::assertTrue($onlineTable->getIndex('simple_partial_index')->hasOption('where'));
385
        self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where'));
386
    }
387
388
    /**
389
     * @dataProvider jsonbColumnTypeProvider
390
     */
391
    public function testJsonbColumn(string $type) : void
392
    {
393
        if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) {
394
            $this->markTestSkipped('Requires PostgresSQL 9.4+');
395
396
            return;
397
        }
398
399
        $table = new Schema\Table('test_jsonb');
400
        $table->addColumn('foo', $type)->setPlatformOption('jsonb', true);
401
        $this->schemaManager->dropAndCreateTable($table);
402
403
        $columns = $this->schemaManager->listTableColumns('test_jsonb');
404
405
        self::assertSame($type, $columns['foo']->getType()->getName());
406
        self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb'));
407
    }
408
409
    /**
410
     * @return mixed[][]
411
     */
412
    public function jsonbColumnTypeProvider() : array
413
    {
414
        return [
415
            [Types::JSON],
416
            [Types::JSON_ARRAY],
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Types::JSON_ARRAY has been deprecated: json_array type is deprecated, use {@see DefaultTypes::JSON} instead. ( Ignorable by Annotation )

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

416
            [/** @scrutinizer ignore-deprecated */ Types::JSON_ARRAY],

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

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

Loading history...
417
        ];
418
    }
419
420
    /**
421
     * @group DBAL-2427
422
     */
423
    public function testListNegativeColumnDefaultValue() : void
424
    {
425
        $table = new Schema\Table('test_default_negative');
426
        $table->addColumn('col_smallint', 'smallint', ['default' => -1]);
427
        $table->addColumn('col_integer', 'integer', ['default' => -1]);
428
        $table->addColumn('col_bigint', 'bigint', ['default' => -1]);
429
        $table->addColumn('col_float', 'float', ['default' => -1.1]);
430
        $table->addColumn('col_decimal', 'decimal', ['default' => -1.1]);
431
        $table->addColumn('col_string', 'string', ['default' => '(-1)']);
432
433
        $this->schemaManager->dropAndCreateTable($table);
434
435
        $columns = $this->schemaManager->listTableColumns('test_default_negative');
436
437
        self::assertEquals(-1, $columns['col_smallint']->getDefault());
438
        self::assertEquals(-1, $columns['col_integer']->getDefault());
439
        self::assertEquals(-1, $columns['col_bigint']->getDefault());
440
        self::assertEquals(-1.1, $columns['col_float']->getDefault());
441
        self::assertEquals(-1.1, $columns['col_decimal']->getDefault());
442
        self::assertEquals('(-1)', $columns['col_string']->getDefault());
443
    }
444
445
    /**
446
     * @return mixed[][]
447
     */
448
    public static function serialTypes() : iterable
449
    {
450
        return [
451
            ['integer'],
452
            ['bigint'],
453
        ];
454
    }
455
456
    /**
457
     * @dataProvider serialTypes
458
     * @group 2906
459
     */
460
    public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValue(string $type) : void
461
    {
462
        $tableName = 'test_serial_type_' . $type;
463
464
        $table = new Schema\Table($tableName);
465
        $table->addColumn('id', $type, ['autoincrement' => true, 'notnull' => false]);
466
467
        $this->schemaManager->dropAndCreateTable($table);
468
469
        $columns = $this->schemaManager->listTableColumns($tableName);
470
471
        self::assertNull($columns['id']->getDefault());
472
    }
473
474
    /**
475
     * @dataProvider serialTypes
476
     * @group 2906
477
     */
478
    public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValueEvenWhenDefaultIsSet(string $type) : void
479
    {
480
        $tableName = 'test_serial_type_with_default_' . $type;
481
482
        $table = new Schema\Table($tableName);
483
        $table->addColumn('id', $type, ['autoincrement' => true, 'notnull' => false, 'default' => 1]);
484
485
        $this->schemaManager->dropAndCreateTable($table);
486
487
        $columns = $this->schemaManager->listTableColumns($tableName);
488
489
        self::assertNull($columns['id']->getDefault());
490
    }
491
492
    /**
493
     * @group 2916
494
     * @dataProvider autoIncrementTypeMigrations
495
     */
496
    public function testAlterTableAutoIncrementIntToBigInt(string $from, string $to, string $expected) : void
497
    {
498
        $tableFrom = new Table('autoinc_type_modification');
499
        $column    = $tableFrom->addColumn('id', $from);
500
        $column->setAutoincrement(true);
501
        $this->schemaManager->dropAndCreateTable($tableFrom);
502
        $tableFrom = $this->schemaManager->listTableDetails('autoinc_type_modification');
503
        self::assertTrue($tableFrom->getColumn('id')->getAutoincrement());
504
505
        $tableTo = new Table('autoinc_type_modification');
506
        $column  = $tableTo->addColumn('id', $to);
507
        $column->setAutoincrement(true);
508
509
        $c    = new Comparator();
510
        $diff = $c->diffTable($tableFrom, $tableTo);
511
        self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison');
512
        self::assertSame(['ALTER TABLE autoinc_type_modification ALTER id TYPE ' . $expected], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff));
513
514
        $this->schemaManager->alterTable($diff);
515
        $tableFinal = $this->schemaManager->listTableDetails('autoinc_type_modification');
516
        self::assertTrue($tableFinal->getColumn('id')->getAutoincrement());
517
    }
518
519
    public function testQuotingMixedCaseAssets() : void
520
    {
521
        $table = new Table('mixedCaseTable');
522
        $table->addColumn('mixedCaseColumn', 'text');
523
        $this->schemaManager->createTable($table);
524
        $columns = $this->schemaManager->listTableColumns('mixedCaseTable');
525
        self::assertCount(1, $columns);
526
        self::assertSame('mixedCaseColumn', current($columns)->getName());
527
    }
528
529
    /**
530
     * @return mixed[][]
531
     */
532
    public static function autoIncrementTypeMigrations() : iterable
533
    {
534
        return [
535
            'int->bigint' => ['integer', 'bigint', 'BIGINT'],
536
            'bigint->int' => ['bigint', 'integer', 'INT'],
537
        ];
538
    }
539
}
540
541
class MoneyType extends Type
542
{
543
    /**
544
     * {@inheritDoc}
545
     */
546
    public function getName()
547
    {
548
        return 'MyMoney';
549
    }
550
551
    /**
552
     * {@inheritDoc}
553
     */
554
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
555
    {
556
        return 'MyMoney';
557
    }
558
}
559