Completed
Pull Request — master (#3206)
by Ilya
39:07 queued 24:33
created

testAutoincrementResetsOnTruncate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 24
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Functional;
4
5
use Doctrine\DBAL\Schema\AbstractSchemaManager;
6
use Doctrine\DBAL\Schema\Table;
7
use Doctrine\Tests\DbalFunctionalTestCase;
8
use const CASE_LOWER;
9
use function array_change_key_case;
10
11
class ResetAutoincrementTest extends DbalFunctionalTestCase
12
{
13
    public function testAutoincrementResetsOnTruncate()
14
    {
15
        $table = new Table('autoincremented_table');
16
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
17
        $table->addColumn('test_int', 'integer');
18
        $table->setPrimaryKey(['id']);
19
20
        /** @var AbstractSchemaManager $sm */
21
        $sm = $this->connection->getSchemaManager();
22
        $sm->createTable($table);
23
24
        $this->connection->insert('autoincremented_table', ['test_int' => 1]);
25
        $this->connection->insert('autoincremented_table', ['test_int' => 2]);
26
        $this->connection->insert('autoincremented_table', ['test_int' => 3]);
27
28
        $lastId = $this->getIdByTestInt(3);
29
30
        $this->assertEquals(3, $lastId);
31
32
        $this->connection->exec($this->connection->getDatabasePlatform()->getTruncateTableSQL('autoincremented_table'));
33
34
        $this->connection->insert('autoincremented_table', ['test_int' => 4]);
35
        $lastId = $this->getIdByTestInt(4);
36
        $this->assertEquals(1, $lastId);
37
    }
38
39
    protected function getIdByTestInt(int $whereTestInt)
40
    {
41
        $row = $this->connection->fetchAssoc('SELECT id FROM autoincremented_table WHERE test_int = ?', [$whereTestInt]);
42
        $row = array_change_key_case($row, CASE_LOWER);
0 ignored issues
show
Bug introduced by
It seems like $row can also be of type false; however, parameter $input of array_change_key_case() does only seem to accept array, 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

42
        $row = array_change_key_case(/** @scrutinizer ignore-type */ $row, CASE_LOWER);
Loading history...
43
44
        return $row['id'];
45
    }
46
}
47