Completed
Pull Request — develop (#3565)
by Jonathan
61:48
created

testListTableColumnsThrowsDatabaseRequired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\DBAL\Functional\Schema;
6
7
use DateTime;
8
use Doctrine\DBAL\DriverManager;
9
use Doctrine\DBAL\Exception\DatabaseRequired;
10
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
11
use Doctrine\DBAL\Platforms\MySqlPlatform;
12
use Doctrine\DBAL\Schema\Comparator;
13
use Doctrine\DBAL\Schema\Schema;
14
use Doctrine\DBAL\Schema\Table;
15
use Doctrine\DBAL\Types\Type;
16
use Doctrine\DBAL\Types\Types;
17
use Doctrine\Tests\TestUtil;
18
use Doctrine\Tests\Types\MySqlPointType;
19
20
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
21
{
22
    protected function setUp() : void
23
    {
24
        parent::setUp();
25
26
        if (Type::hasType('point')) {
27
            return;
28
        }
29
30
        $this->resetSharedConn();
31
32
        Type::addType('point', MySqlPointType::class);
33
    }
34
35
    public function testSwitchPrimaryKeyColumns()
36
    {
37
        $tableOld = new Table('switch_primary_key_columns');
38
        $tableOld->addColumn('foo_id', 'integer');
39
        $tableOld->addColumn('bar_id', 'integer');
40
41
        $this->schemaManager->createTable($tableOld);
42
        $tableFetched = $this->schemaManager->listTableDetails('switch_primary_key_columns');
43
        $tableNew     = clone $tableFetched;
44
        $tableNew->setPrimaryKey(['bar_id', 'foo_id']);
45
46
        $comparator = new Comparator();
47
        $this->schemaManager->alterTable($comparator->diffTable($tableFetched, $tableNew));
48
49
        $table      = $this->schemaManager->listTableDetails('switch_primary_key_columns');
50
        $primaryKey = $table->getPrimaryKeyColumns();
51
52
        self::assertCount(2, $primaryKey);
53
        self::assertContains('bar_id', $primaryKey);
54
        self::assertContains('foo_id', $primaryKey);
55
    }
56
57
    public function testDiffTableBug()
58
    {
59
        $schema = new Schema();
60
        $table  = $schema->createTable('diffbug_routing_translations');
61
        $table->addColumn('id', 'integer');
62
        $table->addColumn('route', 'string');
63
        $table->addColumn('locale', 'string');
64
        $table->addColumn('attribute', 'string');
65
        $table->addColumn('localized_value', 'string');
66
        $table->addColumn('original_value', 'string');
67
        $table->setPrimaryKey(['id']);
68
        $table->addUniqueIndex(['route', 'locale', 'attribute']);
69
        $table->addIndex(['localized_value']); // this is much more selective than the unique index
70
71
        $this->schemaManager->createTable($table);
72
        $tableFetched = $this->schemaManager->listTableDetails('diffbug_routing_translations');
73
74
        $comparator = new Comparator();
75
        $diff       = $comparator->diffTable($tableFetched, $table);
76
77
        self::assertNull($diff, 'no changes expected.');
78
    }
79
80
    public function testFulltextIndex()
81
    {
82
        $table = new Table('fulltext_index');
83
        $table->addColumn('text', 'text');
84
        $table->addIndex(['text'], 'f_index');
85
        $table->addOption('engine', 'MyISAM');
86
87
        $index = $table->getIndex('f_index');
88
        $index->addFlag('fulltext');
89
90
        $this->schemaManager->dropAndCreateTable($table);
91
92
        $indexes = $this->schemaManager->listTableIndexes('fulltext_index');
93
        self::assertArrayHasKey('f_index', $indexes);
94
        self::assertTrue($indexes['f_index']->hasFlag('fulltext'));
95
    }
96
97
    public function testSpatialIndex()
98
    {
99
        $table = new Table('spatial_index');
100
        $table->addColumn('point', 'point');
101
        $table->addIndex(['point'], 's_index');
102
        $table->addOption('engine', 'MyISAM');
103
104
        $index = $table->getIndex('s_index');
105
        $index->addFlag('spatial');
106
107
        $this->schemaManager->dropAndCreateTable($table);
108
109
        $indexes = $this->schemaManager->listTableIndexes('spatial_index');
110
        self::assertArrayHasKey('s_index', $indexes);
111
        self::assertTrue($indexes['s_index']->hasFlag('spatial'));
112
    }
113
114
    public function testIndexWithLength() : void
115
    {
116
        $table = new Table('index_length');
117
        $table->addColumn('text', 'string', ['length' => 255]);
118
        $table->addIndex(['text'], 'text_index', [], ['lengths' => [128]]);
119
120
        $this->schemaManager->dropAndCreateTable($table);
121
122
        $indexes = $this->schemaManager->listTableIndexes('index_length');
123
        self::assertArrayHasKey('text_index', $indexes);
124
        self::assertSame([128], $indexes['text_index']->getOption('lengths'));
125
    }
126
127
    /**
128
     * @group DBAL-400
129
     */
130
    public function testAlterTableAddPrimaryKey()
131
    {
132
        $table = new Table('alter_table_add_pk');
133
        $table->addColumn('id', 'integer');
134
        $table->addColumn('foo', 'integer');
135
        $table->addIndex(['id'], 'idx_id');
136
137
        $this->schemaManager->createTable($table);
138
139
        $comparator = new Comparator();
140
        $diffTable  = clone $table;
141
142
        $diffTable->dropIndex('idx_id');
143
        $diffTable->setPrimaryKey(['id']);
144
145
        $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable));
146
147
        $table = $this->schemaManager->listTableDetails('alter_table_add_pk');
148
149
        self::assertFalse($table->hasIndex('idx_id'));
150
        self::assertTrue($table->hasPrimaryKey());
151
    }
152
153
    /**
154
     * @group DBAL-464
155
     */
156
    public function testDropPrimaryKeyWithAutoincrementColumn()
157
    {
158
        $table = new Table('drop_primary_key');
159
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
160
        $table->addColumn('foo', 'integer');
161
        $table->setPrimaryKey(['id', 'foo']);
162
163
        $this->schemaManager->dropAndCreateTable($table);
164
165
        $diffTable = clone $table;
166
167
        $diffTable->dropPrimaryKey();
168
169
        $comparator = new Comparator();
170
171
        $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable));
172
173
        $table = $this->schemaManager->listTableDetails('drop_primary_key');
174
175
        self::assertFalse($table->hasPrimaryKey());
176
        self::assertFalse($table->getColumn('id')->getAutoincrement());
177
    }
178
179
    /**
180
     * @group DBAL-789
181
     */
182
    public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
183
    {
184
        if ($this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) {
185
            $this->markTestSkipped(
186
                'MariaDb102Platform supports default values for BLOB and TEXT columns and will propagate values'
187
            );
188
        }
189
190
        $table = new Table('text_blob_default_value');
191
        $table->addColumn('def_text', 'text', ['default' => 'def']);
192
        $table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']);
193
        $table->addColumn('def_blob', 'blob', ['default' => 'def']);
194
        $table->addColumn('def_blob_null', 'blob', ['notnull' => false, 'default' => 'def']);
195
196
        $this->schemaManager->dropAndCreateTable($table);
197
198
        $onlineTable = $this->schemaManager->listTableDetails('text_blob_default_value');
199
200
        self::assertNull($onlineTable->getColumn('def_text')->getDefault());
201
        self::assertNull($onlineTable->getColumn('def_text_null')->getDefault());
202
        self::assertFalse($onlineTable->getColumn('def_text_null')->getNotnull());
203
        self::assertNull($onlineTable->getColumn('def_blob')->getDefault());
204
        self::assertNull($onlineTable->getColumn('def_blob_null')->getDefault());
205
        self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull());
206
207
        $comparator = new Comparator();
208
209
        $this->schemaManager->alterTable($comparator->diffTable($table, $onlineTable));
210
211
        $onlineTable = $this->schemaManager->listTableDetails('text_blob_default_value');
212
213
        self::assertNull($onlineTable->getColumn('def_text')->getDefault());
214
        self::assertNull($onlineTable->getColumn('def_text_null')->getDefault());
215
        self::assertFalse($onlineTable->getColumn('def_text_null')->getNotnull());
216
        self::assertNull($onlineTable->getColumn('def_blob')->getDefault());
217
        self::assertNull($onlineTable->getColumn('def_blob_null')->getDefault());
218
        self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull());
219
    }
220
221
    public function testColumnCharset()
222
    {
223
        $table = new Table('test_column_charset');
224
        $table->addColumn('id', 'integer');
225
        $table->addColumn('no_charset', 'text');
226
        $table->addColumn('foo', 'text')->setPlatformOption('charset', 'ascii');
227
        $table->addColumn('bar', 'text')->setPlatformOption('charset', 'latin1');
228
        $this->schemaManager->dropAndCreateTable($table);
229
230
        $columns = $this->schemaManager->listTableColumns('test_column_charset');
231
232
        self::assertFalse($columns['id']->hasPlatformOption('charset'));
233
        self::assertEquals('utf8', $columns['no_charset']->getPlatformOption('charset'));
234
        self::assertEquals('ascii', $columns['foo']->getPlatformOption('charset'));
235
        self::assertEquals('latin1', $columns['bar']->getPlatformOption('charset'));
236
    }
237
238
    public function testAlterColumnCharset()
239
    {
240
        $tableName = 'test_alter_column_charset';
241
242
        $table = new Table($tableName);
243
        $table->addColumn('col_text', 'text')->setPlatformOption('charset', 'utf8');
244
245
        $this->schemaManager->dropAndCreateTable($table);
246
247
        $diffTable = clone $table;
248
        $diffTable->getColumn('col_text')->setPlatformOption('charset', 'ascii');
249
250
        $comparator = new Comparator();
251
252
        $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable));
253
254
        $table = $this->schemaManager->listTableDetails($tableName);
255
256
        self::assertEquals('ascii', $table->getColumn('col_text')->getPlatformOption('charset'));
257
    }
258
259
    public function testColumnCharsetChange()
260
    {
261
        $table = new Table('test_column_charset_change');
262
        $table->addColumn('col_string', 'string')->setLength(100)->setNotnull(true)->setPlatformOption('charset', 'utf8');
263
264
        $diffTable = clone $table;
265
        $diffTable->getColumn('col_string')->setPlatformOption('charset', 'ascii');
266
267
        $fromSchema = new Schema([$table]);
268
        $toSchema   = new Schema([$diffTable]);
269
270
        $diff = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());
271
        self::assertContains('ALTER TABLE test_column_charset_change CHANGE col_string col_string VARCHAR(100) CHARACTER SET ascii NOT NULL', $diff);
272
    }
273
274
    public function testColumnCollation()
275
    {
276
        $table                                  = new Table('test_collation');
277
        $table->addOption('collate', $collation = 'latin1_swedish_ci');
278
        $table->addOption('charset', 'latin1');
279
        $table->addColumn('id', 'integer');
280
        $table->addColumn('text', 'text');
281
        $table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci');
282
        $table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci');
283
        $this->schemaManager->dropAndCreateTable($table);
284
285
        $columns = $this->schemaManager->listTableColumns('test_collation');
286
287
        self::assertArrayNotHasKey('collation', $columns['id']->getPlatformOptions());
288
        self::assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation'));
289
        self::assertEquals('latin1_swedish_ci', $columns['foo']->getPlatformOption('collation'));
290
        self::assertEquals('utf8_general_ci', $columns['bar']->getPlatformOption('collation'));
291
    }
292
293
    /**
294
     * @group DBAL-843
295
     */
296
    public function testListLobTypeColumns()
297
    {
298
        $tableName = 'lob_type_columns';
299
        $table     = new Table($tableName);
300
301
        $table->addColumn('col_tinytext', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TINYTEXT]);
302
        $table->addColumn('col_text', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TEXT]);
303
        $table->addColumn('col_mediumtext', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMTEXT]);
304
        $table->addColumn('col_longtext', 'text');
305
306
        $table->addColumn('col_tinyblob', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TINYBLOB]);
307
        $table->addColumn('col_blob', 'blob', ['length' => MySqlPlatform::LENGTH_LIMIT_BLOB]);
308
        $table->addColumn('col_mediumblob', 'blob', ['length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB]);
309
        $table->addColumn('col_longblob', 'blob');
310
311
        $this->schemaManager->dropAndCreateTable($table);
312
313
        $platform       = $this->schemaManager->getDatabasePlatform();
314
        $offlineColumns = $table->getColumns();
315
        $onlineColumns  = $this->schemaManager->listTableColumns($tableName);
316
317
        self::assertSame(
318
            $platform->getClobTypeDeclarationSQL($offlineColumns['col_tinytext']->toArray()),
319
            $platform->getClobTypeDeclarationSQL($onlineColumns['col_tinytext']->toArray())
320
        );
321
        self::assertSame(
322
            $platform->getClobTypeDeclarationSQL($offlineColumns['col_text']->toArray()),
323
            $platform->getClobTypeDeclarationSQL($onlineColumns['col_text']->toArray())
324
        );
325
        self::assertSame(
326
            $platform->getClobTypeDeclarationSQL($offlineColumns['col_mediumtext']->toArray()),
327
            $platform->getClobTypeDeclarationSQL($onlineColumns['col_mediumtext']->toArray())
328
        );
329
        self::assertSame(
330
            $platform->getClobTypeDeclarationSQL($offlineColumns['col_longtext']->toArray()),
331
            $platform->getClobTypeDeclarationSQL($onlineColumns['col_longtext']->toArray())
332
        );
333
334
        self::assertSame(
335
            $platform->getBlobTypeDeclarationSQL($offlineColumns['col_tinyblob']->toArray()),
336
            $platform->getBlobTypeDeclarationSQL($onlineColumns['col_tinyblob']->toArray())
337
        );
338
        self::assertSame(
339
            $platform->getBlobTypeDeclarationSQL($offlineColumns['col_blob']->toArray()),
340
            $platform->getBlobTypeDeclarationSQL($onlineColumns['col_blob']->toArray())
341
        );
342
        self::assertSame(
343
            $platform->getBlobTypeDeclarationSQL($offlineColumns['col_mediumblob']->toArray()),
344
            $platform->getBlobTypeDeclarationSQL($onlineColumns['col_mediumblob']->toArray())
345
        );
346
        self::assertSame(
347
            $platform->getBlobTypeDeclarationSQL($offlineColumns['col_longblob']->toArray()),
348
            $platform->getBlobTypeDeclarationSQL($onlineColumns['col_longblob']->toArray())
349
        );
350
    }
351
352
    /**
353
     * @group DBAL-423
354
     */
355
    public function testDiffListGuidTableColumn()
356
    {
357
        $offlineTable = new Table('list_guid_table_column');
358
        $offlineTable->addColumn('col_guid', 'guid');
359
360
        $this->schemaManager->dropAndCreateTable($offlineTable);
361
362
        $onlineTable = $this->schemaManager->listTableDetails('list_guid_table_column');
363
364
        $comparator = new Comparator();
365
366
        self::assertNull(
367
            $comparator->diffTable($offlineTable, $onlineTable),
368
            'No differences should be detected with the offline vs online schema.'
369
        );
370
    }
371
372
    /**
373
     * @group DBAL-1082
374
     */
375
    public function testListDecimalTypeColumns()
376
    {
377
        $tableName = 'test_list_decimal_columns';
378
        $table     = new Table($tableName);
379
380
        $table->addColumn('col', 'decimal');
381
        $table->addColumn('col_unsigned', 'decimal', ['unsigned' => true]);
382
383
        $this->schemaManager->dropAndCreateTable($table);
384
385
        $columns = $this->schemaManager->listTableColumns($tableName);
386
387
        self::assertArrayHasKey('col', $columns);
388
        self::assertArrayHasKey('col_unsigned', $columns);
389
        self::assertFalse($columns['col']->getUnsigned());
390
        self::assertTrue($columns['col_unsigned']->getUnsigned());
391
    }
392
393
    /**
394
     * @group DBAL-1082
395
     */
396
    public function testListFloatTypeColumns()
397
    {
398
        $tableName = 'test_list_float_columns';
399
        $table     = new Table($tableName);
400
401
        $table->addColumn('col', 'float');
402
        $table->addColumn('col_unsigned', 'float', ['unsigned' => true]);
403
404
        $this->schemaManager->dropAndCreateTable($table);
405
406
        $columns = $this->schemaManager->listTableColumns($tableName);
407
408
        self::assertArrayHasKey('col', $columns);
409
        self::assertArrayHasKey('col_unsigned', $columns);
410
        self::assertFalse($columns['col']->getUnsigned());
411
        self::assertTrue($columns['col_unsigned']->getUnsigned());
412
    }
413
414
    public function testJsonColumnType() : void
415
    {
416
        $table = new Table('test_mysql_json');
417
        $table->addColumn('col_json', 'json');
418
        $this->schemaManager->dropAndCreateTable($table);
419
420
        $columns = $this->schemaManager->listTableColumns('test_mysql_json');
421
422
        self::assertSame(Types::JSON, $columns['col_json']->getType()->getName());
423
    }
424
425
    public function testColumnDefaultCurrentTimestamp() : void
426
    {
427
        $platform = $this->schemaManager->getDatabasePlatform();
428
429
        $table = new Table('test_column_defaults_current_timestamp');
430
431
        $currentTimeStampSql = $platform->getCurrentTimestampSQL();
432
433
        $table->addColumn('col_datetime', 'datetime', ['notnull' => true, 'default' => $currentTimeStampSql]);
434
        $table->addColumn('col_datetime_nullable', 'datetime', ['default' => $currentTimeStampSql]);
435
436
        $this->schemaManager->dropAndCreateTable($table);
437
438
        $onlineTable = $this->schemaManager->listTableDetails('test_column_defaults_current_timestamp');
439
        self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime')->getDefault());
440
        self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime_nullable')->getDefault());
441
442
        $comparator = new Comparator();
443
444
        $diff = $comparator->diffTable($table, $onlineTable);
445
        self::assertNull($diff, 'Tables should be identical with column defaults.');
446
    }
447
448
    public function testColumnDefaultsAreValid()
449
    {
450
        $table = new Table('test_column_defaults_are_valid');
451
452
        $currentTimeStampSql = $this->schemaManager->getDatabasePlatform()->getCurrentTimestampSQL();
453
        $table->addColumn('col_datetime', 'datetime', ['default' => $currentTimeStampSql]);
454
        $table->addColumn('col_datetime_null', 'datetime', ['notnull' => false, 'default' => null]);
455
        $table->addColumn('col_int', 'integer', ['default' => 1]);
456
        $table->addColumn('col_neg_int', 'integer', ['default' => -1]);
457
        $table->addColumn('col_string', 'string', ['default' => 'A']);
458
        $table->addColumn('col_decimal', 'decimal', ['scale' => 3, 'precision' => 6, 'default' => -2.3]);
459
        $table->addColumn('col_date', 'date', ['default' => '2012-12-12']);
460
461
        $this->schemaManager->dropAndCreateTable($table);
462
463
        $this->connection->executeUpdate(
464
            'INSERT INTO test_column_defaults_are_valid () VALUES()'
465
        );
466
467
        $row = $this->connection->fetchAssoc(
468
            'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid'
469
        );
470
471
        self::assertInstanceOf(DateTime::class, DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime']));
472
        self::assertNull($row['col_datetime_null']);
473
        self::assertSame('2012-12-12', $row['col_date']);
474
        self::assertSame('A', $row['col_string']);
475
        self::assertEquals(1, $row['col_int']);
476
        self::assertEquals(-1, $row['col_neg_int']);
477
        self::assertEquals('-2.300', $row['col_decimal']);
478
        self::assertLessThan(5, $row['diff_seconds']);
479
    }
480
481
    /**
482
     * MariaDB 10.2+ does support CURRENT_TIME and CURRENT_DATE as
483
     * column default values for time and date columns.
484
     * (Not supported on Mysql as of 5.7.19)
485
     *
486
     * Note that MariaDB 10.2+, when storing default in information_schema,
487
     * silently change CURRENT_TIMESTAMP as 'current_timestamp()',
488
     * CURRENT_TIME as 'currtime()' and CURRENT_DATE as 'currdate()'.
489
     * This test also ensure proper aliasing to not trigger a table diff.
490
     */
491
    public function testColumnDefaultValuesCurrentTimeAndDate() : void
492
    {
493
        if (! $this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) {
494
            $this->markTestSkipped('Only relevant for MariaDb102Platform.');
495
        }
496
497
        $platform = $this->schemaManager->getDatabasePlatform();
498
499
        $table = new Table('test_column_defaults_current_time_and_date');
500
501
        $currentTimestampSql = $platform->getCurrentTimestampSQL();
502
        $currentTimeSql      = $platform->getCurrentTimeSQL();
503
        $currentDateSql      = $platform->getCurrentDateSQL();
504
505
        $table->addColumn('col_datetime', 'datetime', ['default' => $currentTimestampSql]);
506
        $table->addColumn('col_date', 'date', ['default' => $currentDateSql]);
507
        $table->addColumn('col_time', 'time', ['default' => $currentTimeSql]);
508
509
        $this->schemaManager->dropAndCreateTable($table);
510
511
        $onlineTable = $this->schemaManager->listTableDetails('test_column_defaults_current_time_and_date');
512
513
        self::assertSame($currentTimestampSql, $onlineTable->getColumn('col_datetime')->getDefault());
514
        self::assertSame($currentDateSql, $onlineTable->getColumn('col_date')->getDefault());
515
        self::assertSame($currentTimeSql, $onlineTable->getColumn('col_time')->getDefault());
516
517
        $comparator = new Comparator();
518
519
        $diff = $comparator->diffTable($table, $onlineTable);
520
        self::assertNull($diff, 'Tables should be identical with column defauts time and date.');
521
    }
522
523
    public function testEnsureTableOptionsAreReflectedInMetadata() : void
524
    {
525
        $this->connection->query('DROP TABLE IF EXISTS test_table_metadata');
526
527
        $sql = <<<'SQL'
528
CREATE TABLE test_table_metadata(
529
  col1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY
530
)
531
COLLATE utf8_general_ci
532
ENGINE InnoDB
533
ROW_FORMAT COMPRESSED
534
COMMENT 'This is a test'
535
AUTO_INCREMENT=42
536
PARTITION BY HASH (col1)
537
SQL;
538
539
        $this->connection->query($sql);
540
        $onlineTable = $this->schemaManager->listTableDetails('test_table_metadata');
541
542
        self::assertEquals('InnoDB', $onlineTable->getOption('engine'));
543
        self::assertEquals('utf8_general_ci', $onlineTable->getOption('collation'));
544
        self::assertEquals(42, $onlineTable->getOption('autoincrement'));
545
        self::assertEquals('This is a test', $onlineTable->getOption('comment'));
546
        self::assertEquals([
547
            'row_format' => 'COMPRESSED',
548
            'partitioned' => true,
549
        ], $onlineTable->getOption('create_options'));
550
    }
551
552
    public function testEnsureTableWithoutOptionsAreReflectedInMetadata() : void
553
    {
554
        $this->connection->query('DROP TABLE IF EXISTS test_table_empty_metadata');
555
556
        $this->connection->query('CREATE TABLE test_table_empty_metadata(col1 INT NOT NULL)');
557
        $onlineTable = $this->schemaManager->listTableDetails('test_table_empty_metadata');
558
559
        self::assertNotEmpty($onlineTable->getOption('engine'));
560
        // collation could be set to default or not set, information_schema indicate a possibly null value
561
        self::assertFalse($onlineTable->hasOption('autoincrement'));
562
        self::assertEquals('', $onlineTable->getOption('comment'));
563
        self::assertEquals([], $onlineTable->getOption('create_options'));
564
    }
565
566
    public function testParseNullCreateOptions() : void
567
    {
568
        $table = $this->schemaManager->listTableDetails('sys.processlist');
569
570
        self::assertEquals([], $table->getOption('create_options'));
571
    }
572
573
    public function testListTableColumnsThrowsDatabaseRequired() : void
574
    {
575
        $params = TestUtil::getConnectionParams();
576
        unset($params['dbname']);
577
578
        $connection    = DriverManager::getConnection($params);
579
        $schemaManager = $connection->getSchemaManager();
580
581
        self::expectException(DatabaseRequired::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

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

581
        self::/** @scrutinizer ignore-call */ 
582
              expectException(DatabaseRequired::class);
Loading history...
582
        self::expectExceptionMessage('A database is required for the method: Doctrine\DBAL\Schema\AbstractSchemaManager::listTableColumns');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

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

582
        self::/** @scrutinizer ignore-call */ 
583
              expectExceptionMessage('A database is required for the method: Doctrine\DBAL\Schema\AbstractSchemaManager::listTableColumns');
Loading history...
583
584
        $schemaManager->listTableColumns('users');
585
    }
586
}
587