Passed
Pull Request — master (#2916)
by Robin
15:32
created

testAlterTableAutoIncrementBigInt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 21
loc 21
rs 9.3142
cc 1
eloc 16
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\Table;
10
use Doctrine\DBAL\Types\Type;
11
12
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
13
{
14
    protected function tearDown()
15
    {
16
        parent::tearDown();
17
18
        if (!$this->_conn) {
19
            return;
20
        }
21
22
        $this->_conn->getConfiguration()->setFilterSchemaAssetsExpression(null);
23
    }
24
25
    /**
26
     * @group DBAL-177
27
     */
28
    public function testGetSearchPath()
29
    {
30
        $params = $this->_conn->getParams();
31
32
        $paths = $this->_sm->getSchemaSearchPaths();
33
        self::assertEquals([$params['user'], 'public'], $paths);
34
    }
35
36
    /**
37
     * @group DBAL-244
38
     */
39
    public function testGetSchemaNames()
40
    {
41
        $names = $this->_sm->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

41
        /** @scrutinizer ignore-call */ 
42
        $names = $this->_sm->getSchemaNames();
Loading history...
42
43
        self::assertInternalType('array', $names);
44
        self::assertTrue(count($names) > 0);
45
        self::assertContains('public', $names, 'The public schema should be found.');
46
    }
47
48
    /**
49
     * @group DBAL-21
50
     */
51
    public function testSupportDomainTypeFallback()
52
    {
53
        $createDomainTypeSQL = "CREATE DOMAIN MyMoney AS DECIMAL(18,2)";
54
        $this->_conn->exec($createDomainTypeSQL);
55
56
        $createTableSQL = "CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)";
57
        $this->_conn->exec($createTableSQL);
58
59
        $table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test');
60
        self::assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $table->getColumn('value')->getType());
61
62
        Type::addType('MyMoney', 'Doctrine\Tests\DBAL\Functional\Schema\MoneyType');
63
        $this->_conn->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney', 'MyMoney');
64
65
        $table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test');
66
        self::assertInstanceOf('Doctrine\Tests\DBAL\Functional\Schema\MoneyType', $table->getColumn('value')->getType());
67
    }
68
69
    /**
70
     * @group DBAL-37
71
     */
72
    public function testDetectsAutoIncrement()
73
    {
74
        $autoincTable = new \Doctrine\DBAL\Schema\Table('autoinc_table');
75
        $column = $autoincTable->addColumn('id', 'integer');
76
        $column->setAutoincrement(true);
77
        $this->_sm->createTable($autoincTable);
78
        $autoincTable = $this->_sm->listTableDetails('autoinc_table');
79
80
        self::assertTrue($autoincTable->getColumn('id')->getAutoincrement());
81
    }
82
83
    /**
84
     * @group DBAL-37
85
     */
86 View Code Duplication
    public function testAlterTableAutoIncrementAdd()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $tableFrom = new \Doctrine\DBAL\Schema\Table('autoinc_table_add');
89
        $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...
90
        $this->_sm->createTable($tableFrom);
91
        $tableFrom = $this->_sm->listTableDetails('autoinc_table_add');
92
        self::assertFalse($tableFrom->getColumn('id')->getAutoincrement());
93
94
        $tableTo = new \Doctrine\DBAL\Schema\Table('autoinc_table_add');
95
        $column = $tableTo->addColumn('id', 'integer');
96
        $column->setAutoincrement(true);
97
98
        $c = new \Doctrine\DBAL\Schema\Comparator();
99
        $diff = $c->diffTable($tableFrom, $tableTo);
100
        $sql = $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff);
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type boolean; 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

100
        $sql = $this->_conn->getDatabasePlatform()->getAlterTableSQL(/** @scrutinizer ignore-type */ $diff);
Loading history...
101
        self::assertEquals(array(
102
            "CREATE SEQUENCE autoinc_table_add_id_seq",
103
            "SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))",
104
            "ALTER TABLE autoinc_table_add ALTER id SET DEFAULT nextval('autoinc_table_add_id_seq')",
105
        ), $sql);
106
107
        $this->_sm->alterTable($diff);
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type boolean; however, parameter $tableDiff of Doctrine\DBAL\Schema\Abs...maManager::alterTable() 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

107
        $this->_sm->alterTable(/** @scrutinizer ignore-type */ $diff);
Loading history...
108
        $tableFinal = $this->_sm->listTableDetails('autoinc_table_add');
109
        self::assertTrue($tableFinal->getColumn('id')->getAutoincrement());
110
    }
111
112
    /**
113
     * @group DBAL-37
114
     */
115 View Code Duplication
    public function testAlterTableAutoIncrementDrop()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        $tableFrom = new \Doctrine\DBAL\Schema\Table('autoinc_table_drop');
118
        $column = $tableFrom->addColumn('id', 'integer');
119
        $column->setAutoincrement(true);
120
        $this->_sm->createTable($tableFrom);
121
        $tableFrom = $this->_sm->listTableDetails('autoinc_table_drop');
122
        self::assertTrue($tableFrom->getColumn('id')->getAutoincrement());
123
124
        $tableTo = new \Doctrine\DBAL\Schema\Table('autoinc_table_drop');
125
        $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...
126
127
        $c = new \Doctrine\DBAL\Schema\Comparator();
128
        $diff = $c->diffTable($tableFrom, $tableTo);
129
        self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $diff, "There should be a difference and not false being returned from the table comparison");
130
        self::assertEquals(array("ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT"), $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff));
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type boolean; 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

130
        self::assertEquals(array("ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT"), $this->_conn->getDatabasePlatform()->getAlterTableSQL(/** @scrutinizer ignore-type */ $diff));
Loading history...
131
132
        $this->_sm->alterTable($diff);
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type boolean; however, parameter $tableDiff of Doctrine\DBAL\Schema\Abs...maManager::alterTable() 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

132
        $this->_sm->alterTable(/** @scrutinizer ignore-type */ $diff);
Loading history...
133
        $tableFinal = $this->_sm->listTableDetails('autoinc_table_drop');
134
        self::assertFalse($tableFinal->getColumn('id')->getAutoincrement());
135
    }
136
137
    /**
138
     * @group DBAL-75
139
     */
140
    public function testTableWithSchema()
141
    {
142
        $this->_conn->exec('CREATE SCHEMA nested');
143
144
        $nestedRelatedTable = new \Doctrine\DBAL\Schema\Table('nested.schemarelated');
145
        $column = $nestedRelatedTable->addColumn('id', 'integer');
146
        $column->setAutoincrement(true);
147
        $nestedRelatedTable->setPrimaryKey(array('id'));
148
149
        $nestedSchemaTable = new \Doctrine\DBAL\Schema\Table('nested.schematable');
150
        $column = $nestedSchemaTable->addColumn('id', 'integer');
151
        $column->setAutoincrement(true);
152
        $nestedSchemaTable->setPrimaryKey(array('id'));
153
        $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, array('id'), array('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

153
        /** @scrutinizer ignore-deprecated */ $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, array('id'), array('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...
154
155
        $this->_sm->createTable($nestedRelatedTable);
156
        $this->_sm->createTable($nestedSchemaTable);
157
158
        $tables = $this->_sm->listTableNames();
159
        self::assertContains('nested.schematable', $tables, "The table should be detected with its non-public schema.");
160
161
        $nestedSchemaTable = $this->_sm->listTableDetails('nested.schematable');
162
        self::assertTrue($nestedSchemaTable->hasColumn('id'));
163
        self::assertEquals(array('id'), $nestedSchemaTable->getPrimaryKey()->getColumns());
164
165
        $relatedFks = $nestedSchemaTable->getForeignKeys();
166
        self::assertEquals(1, count($relatedFks));
167
        $relatedFk = array_pop($relatedFks);
168
        self::assertEquals("nested.schemarelated", $relatedFk->getForeignTableName());
169
    }
170
171
    /**
172
     * @group DBAL-91
173
     * @group DBAL-88
174
     */
175
    public function testReturnQuotedAssets()
176
    {
177
        $sql = 'create table dbal91_something ( id integer  CONSTRAINT id_something PRIMARY KEY NOT NULL  ,"table"   integer );';
178
        $this->_conn->exec($sql);
179
180
        $sql = 'ALTER TABLE dbal91_something ADD CONSTRAINT something_input FOREIGN KEY( "table" ) REFERENCES dbal91_something ON UPDATE CASCADE;';
181
        $this->_conn->exec($sql);
182
183
        $table = $this->_sm->listTableDetails('dbal91_something');
184
185
        self::assertEquals(
186
            array(
187
                "CREATE TABLE dbal91_something (id INT NOT NULL, \"table\" INT DEFAULT NULL, PRIMARY KEY(id))",
188
                "CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something (\"table\")",
189
            ),
190
            $this->_conn->getDatabasePlatform()->getCreateTableSQL($table)
191
        );
192
    }
193
194
    /**
195
     * @group DBAL-204
196
     */
197
    public function testFilterSchemaExpression()
198
    {
199
        $testTable = new \Doctrine\DBAL\Schema\Table('dbal204_test_prefix');
200
        $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...
201
        $this->_sm->createTable($testTable);
202
        $testTable = new \Doctrine\DBAL\Schema\Table('dbal204_without_prefix');
203
        $column = $testTable->addColumn('id', 'integer');
204
        $this->_sm->createTable($testTable);
205
206
        $this->_conn->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#');
207
        $names = $this->_sm->listTableNames();
208
        self::assertEquals(2, count($names));
209
210
        $this->_conn->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_test#');
211
        $names = $this->_sm->listTableNames();
212
        self::assertEquals(1, count($names));
213
    }
214
215
    public function testListForeignKeys()
216
    {
217
        if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
218
            $this->markTestSkipped('Does not support foreign key constraints.');
219
        }
220
221
        $fkOptions = array('SET NULL', 'SET DEFAULT', 'NO ACTION','CASCADE', 'RESTRICT');
222
        $foreignKeys = array();
223
        $fkTable = $this->getTestTable('test_create_fk1');
224
        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...
225
            $fkTable->addColumn("foreign_key_test$i", 'integer');
226
            $foreignKeys[] = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(
227
                                 array("foreign_key_test$i"), 'test_create_fk2', array('id'), "foreign_key_test_$i"."_fk", array('onDelete' => $fkOptions[$i]));
228
        }
229
        $this->_sm->dropAndCreateTable($fkTable);
230
        $this->createTestTable('test_create_fk2');
231
232
        foreach($foreignKeys as $foreignKey) {
233
            $this->_sm->createForeignKey($foreignKey, 'test_create_fk1');
234
        }
235
        $fkeys = $this->_sm->listTableForeignKeys('test_create_fk1');
236
        self::assertEquals(count($foreignKeys), count($fkeys), "Table 'test_create_fk1' has to have " . count($foreignKeys) . " foreign keys.");
237
        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...
238
            self::assertEquals(array("foreign_key_test$i"), array_map('strtolower', $fkeys[$i]->getLocalColumns()));
239
            self::assertEquals(array('id'), array_map('strtolower', $fkeys[$i]->getForeignColumns()));
240
            self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName()));
241
            if ($foreignKeys[$i]->getOption('onDelete') == 'NO ACTION') {
242
                self::assertFalse($fkeys[$i]->hasOption('onDelete'), 'Unexpected option: '. $fkeys[$i]->getOption('onDelete'));
243
            } else {
244
                self::assertEquals($foreignKeys[$i]->getOption('onDelete'), $fkeys[$i]->getOption('onDelete'));
245
            }
246
        }
247
    }
248
249
    /**
250
     * @group DBAL-511
251
     */
252
    public function testDefaultValueCharacterVarying()
253
    {
254
        $testTable = new \Doctrine\DBAL\Schema\Table('dbal511_default');
255
        $testTable->addColumn('id', 'integer');
256
        $testTable->addColumn('def', 'string', array('default' => 'foo'));
257
        $testTable->setPrimaryKey(array('id'));
258
259
        $this->_sm->createTable($testTable);
260
261
        $databaseTable = $this->_sm->listTableDetails($testTable->getName());
262
263
        self::assertEquals('foo', $databaseTable->getColumn('def')->getDefault());
264
    }
265
266
    /**
267
     * @group DDC-2843
268
     */
269 View Code Duplication
    public function testBooleanDefault()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
270
    {
271
        $table = new \Doctrine\DBAL\Schema\Table('ddc2843_bools');
272
        $table->addColumn('id', 'integer');
273
        $table->addColumn('checked', 'boolean', array('default' => false));
274
275
        $this->_sm->createTable($table);
276
277
        $databaseTable = $this->_sm->listTableDetails($table->getName());
278
279
        $c = new \Doctrine\DBAL\Schema\Comparator();
280
        $diff = $c->diffTable($table, $databaseTable);
281
282
        self::assertFalse($diff);
283
    }
284
285 View Code Duplication
    public function testListTableWithBinary()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
286
    {
287
        $tableName = 'test_binary_table';
288
289
        $table = new \Doctrine\DBAL\Schema\Table($tableName);
290
        $table->addColumn('id', 'integer');
291
        $table->addColumn('column_varbinary', 'binary', array());
292
        $table->addColumn('column_binary', 'binary', array('fixed' => true));
293
        $table->setPrimaryKey(array('id'));
294
295
        $this->_sm->createTable($table);
296
297
        $table = $this->_sm->listTableDetails($tableName);
298
299
        self::assertInstanceOf('Doctrine\DBAL\Types\BlobType', $table->getColumn('column_varbinary')->getType());
300
        self::assertFalse($table->getColumn('column_varbinary')->getFixed());
301
302
        self::assertInstanceOf('Doctrine\DBAL\Types\BlobType', $table->getColumn('column_binary')->getType());
303
        self::assertFalse($table->getColumn('column_binary')->getFixed());
304
    }
305
306
    public function testListQuotedTable()
307
    {
308
        $offlineTable = new Schema\Table('user');
309
        $offlineTable->addColumn('id', 'integer');
310
        $offlineTable->addColumn('username', 'string', array('unique' => true));
311
        $offlineTable->addColumn('fk', 'integer');
312
        $offlineTable->setPrimaryKey(array('id'));
313
        $offlineTable->addForeignKeyConstraint($offlineTable, array('fk'), array('id'));
314
315
        $this->_sm->dropAndCreateTable($offlineTable);
316
317
        $onlineTable = $this->_sm->listTableDetails('"user"');
318
319
        $comparator = new Schema\Comparator();
320
321
        self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
322
    }
323
324
    public function testListTablesExcludesViews()
325
    {
326
        $this->createTestTable('list_tables_excludes_views');
327
328
        $name = "list_tables_excludes_views_test_view";
329
        $sql = "SELECT * from list_tables_excludes_views";
330
331
        $view = new Schema\View($name, $sql);
332
333
        $this->_sm->dropAndCreateView($view);
334
335
        $tables = $this->_sm->listTables();
336
337
        $foundTable = false;
338 View Code Duplication
        foreach ($tables as $table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
339
            self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.');
340
            if (strtolower($table->getName()) == 'list_tables_excludes_views_test_view') {
341
                $foundTable = true;
342
            }
343
        }
344
345
        self::assertFalse($foundTable, 'View "list_tables_excludes_views_test_view" must not be found in table list');
346
    }
347
348
    /**
349
     * @group DBAL-1033
350
     */
351
    public function testPartialIndexes()
352
    {
353
        $offlineTable = new Schema\Table('person');
354
        $offlineTable->addColumn('id', 'integer');
355
        $offlineTable->addColumn('name', 'string');
356
        $offlineTable->addColumn('email', 'string');
357
        $offlineTable->addUniqueIndex(array('id', 'name'), 'simple_partial_index', array('where' => '(id IS NULL)'));
358
359
        $this->_sm->dropAndCreateTable($offlineTable);
360
361
        $onlineTable = $this->_sm->listTableDetails('person');
362
363
        $comparator = new Schema\Comparator();
364
365
        self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
366
        self::assertTrue($onlineTable->hasIndex('simple_partial_index'));
367
        self::assertTrue($onlineTable->getIndex('simple_partial_index')->hasOption('where'));
368
        self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where'));
369
    }
370
371
    /**
372
     * @dataProvider jsonbColumnTypeProvider
373
     */
374
    public function testJsonbColumn(string $type): void
375
    {
376
        if (!$this->_sm->getDatabasePlatform() instanceof PostgreSQL94Platform) {
377
            $this->markTestSkipped("Requires PostgresSQL 9.4+");
378
            return;
379
        }
380
381
        $table = new Schema\Table('test_jsonb');
382
        $table->addColumn('foo', $type)->setPlatformOption('jsonb', true);
383
        $this->_sm->dropAndCreateTable($table);
384
385
        /** @var Schema\Column[] $columns */
386
        $columns = $this->_sm->listTableColumns('test_jsonb');
387
388
        self::assertSame($type, $columns['foo']->getType()->getName());
389
        self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb'));
390
    }
391
392
    public function jsonbColumnTypeProvider(): array
393
    {
394
        return [
395
            [Type::JSON],
396
            [Type::JSON_ARRAY],
397
        ];
398
    }
399
400
    /**
401
     * @group DBAL-2427
402
     */
403
    public function testListNegativeColumnDefaultValue()
404
    {
405
        $table = new Schema\Table('test_default_negative');
406
        $table->addColumn('col_smallint', 'smallint', array('default' => -1));
407
        $table->addColumn('col_integer', 'integer', array('default' => -1));
408
        $table->addColumn('col_bigint', 'bigint', array('default' => -1));
409
        $table->addColumn('col_float', 'float', array('default' => -1.1));
410
        $table->addColumn('col_decimal', 'decimal', array('default' => -1.1));
411
        $table->addColumn('col_string', 'string', array('default' => '(-1)'));
412
413
        $this->_sm->dropAndCreateTable($table);
414
415
        $columns = $this->_sm->listTableColumns('test_default_negative');
416
417
        self::assertEquals(-1, $columns['col_smallint']->getDefault());
418
        self::assertEquals(-1, $columns['col_integer']->getDefault());
419
        self::assertEquals(-1, $columns['col_bigint']->getDefault());
420
        self::assertEquals(-1.1, $columns['col_float']->getDefault());
421
        self::assertEquals(-1.1, $columns['col_decimal']->getDefault());
422
        self::assertEquals('(-1)', $columns['col_string']->getDefault());
423
    }
424
425
    public static function serialTypes() : array
426
    {
427
        return [
428
            ['integer'],
429
            ['bigint'],
430
        ];
431
    }
432
433
    /**
434
     * @dataProvider serialTypes
435
     * @group 2906
436
     */
437 View Code Duplication
    public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValue(string $type) : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
438
    {
439
        $tableName = "test_serial_type_$type";
440
441
        $table = new Schema\Table($tableName);
442
        $table->addColumn('id', $type, ['autoincrement' => true, 'notnull' => false]);
443
444
        $this->_sm->dropAndCreateTable($table);
445
446
        $columns = $this->_sm->listTableColumns($tableName);
447
448
        self::assertNull($columns['id']->getDefault());
449
    }
450
451
    /**
452
     * @dataProvider serialTypes
453
     * @group 2906
454
     */
455 View Code Duplication
    public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValueEvenWhenDefaultIsSet(string $type) : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
456
    {
457
        $tableName = "test_serial_type_with_default_$type";
458
459
        $table = new Schema\Table($tableName);
460
        $table->addColumn('id', $type, ['autoincrement' => true, 'notnull' => false, 'default' => 1]);
461
462
        $this->_sm->dropAndCreateTable($table);
463
464
        $columns = $this->_sm->listTableColumns($tableName);
465
466
        self::assertNull($columns['id']->getDefault());
467
    }
468
469
    /**
470
     * @group 2916
471
     */
472 View Code Duplication
    public function testAlterTableAutoIncrementBigInt() : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
473
    {
474
        $tableFrom = new Table('autoinc_table_bitgint');
475
        $column = $tableFrom->addColumn('id', 'integer');
476
        $column->setAutoincrement(true);
477
        $this->_sm->createTable($tableFrom);
478
        $tableFrom = $this->_sm->listTableDetails('autoinc_table_bitgint');
479
        self::assertTrue($tableFrom->getColumn('id')->getAutoincrement());
480
481
        $tableTo = new Table('autoinc_table_bitgint');
482
        $column = $tableTo->addColumn('id', 'bigint');
483
        $column->setAutoincrement(true);
484
485
        $c = new Comparator();
486
        $diff = $c->diffTable($tableFrom, $tableTo);
487
        self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $diff, "There should be a difference and not false being returned from the table comparison");
488
        self::assertSame(["ALTER TABLE autoinc_table_bitgint ALTER id TYPE BIGINT"], $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff));
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type boolean; 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

488
        self::assertSame(["ALTER TABLE autoinc_table_bitgint ALTER id TYPE BIGINT"], $this->_conn->getDatabasePlatform()->getAlterTableSQL(/** @scrutinizer ignore-type */ $diff));
Loading history...
489
490
        $this->_sm->alterTable($diff);
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type boolean; however, parameter $tableDiff of Doctrine\DBAL\Schema\Abs...maManager::alterTable() 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

490
        $this->_sm->alterTable(/** @scrutinizer ignore-type */ $diff);
Loading history...
491
        $tableFinal = $this->_sm->listTableDetails('autoinc_table_bitgint');
492
        self::assertTrue($tableFinal->getColumn('id')->getAutoincrement());
493
    }
494
}
495
496
class MoneyType extends Type
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
497
{
498
499
    public function getName()
500
    {
501
        return "MyMoney";
502
    }
503
504
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
505
    {
506
        return 'MyMoney';
507
    }
508
509
}
510