Completed
Pull Request — master (#3311)
by Arne
64:03
created

DBAL2807Test::getPlatform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Functional\Ticket;
4
5
use Doctrine\DBAL\Schema\Comparator;
6
use Doctrine\DBAL\Schema\Table;
7
use Doctrine\Tests\DbalFunctionalTestCase;
8
9
final class DBAL2807Test extends DbalFunctionalTestCase
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14
    public function setUp()
15
    {
16
        parent::setUp();
17
18
        if (!in_array($this->getPlatform()->getName(), ['mysql']))
19
        {
20
            $this->markTestSkipped('Restricted to MySQL.');
21
22
            return;
23
        }
24
    }
25
26
    /**
27
     * Ensures that the primary key is created within the same "alter table" statement that an auto-increment column
28
     * is added to the table as part of the new primary key.
29
     *
30
     * Before the fix for this problem this resulted in a database error:
31
     * SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
32
     */
33
    public function testAlterPrimaryKeyToAutoIncrementColumn()
34
    {
35
        $table = new Table('my_table');
36
        $table->addColumn('initial_id', 'integer');
37
        $table->setPrimaryKey(['initial_id']);
38
39
        $newTable = clone $table;
40
        $newTable->addColumn('new_id', 'integer', ['autoincrement' => true]);
41
        $newTable->dropPrimaryKey();
42
        $newTable->setPrimaryKey(['new_id']);
43
44
        $diff = (new Comparator())->diffTable($table, $newTable);
45
46
        $this->assertSame(
47
            ['ALTER TABLE my_table ADD new_id INT AUTO_INCREMENT NOT NULL, DROP PRIMARY KEY, ADD PRIMARY KEY (new_id)',],
48
            $this->getPlatform()->getAlterTableSQL($diff)
0 ignored issues
show
Bug introduced by
It seems like $diff can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

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

48
            $this->getPlatform()->getAlterTableSQL(/** @scrutinizer ignore-type */ $diff)
Loading history...
49
        );
50
    }
51
52
    protected function getPlatform()
53
    {
54
        return $this->connection->getDatabasePlatform();
55
    }
56
}
57