Completed
Pull Request — master (#3206)
by Ilya
64:15
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 const CASE_LOWER;
6
7
class ResetAutoincrementTest extends \Doctrine\Tests\DbalFunctionalTestCase
8
{
9
    public function testAutoincrementResetsOnTruncate()
10
    {
11
        $table = new \Doctrine\DBAL\Schema\Table('autoincremented_table');
12
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
13
        $table->addColumn('test_int', 'integer');
14
        $table->setPrimaryKey(['id']);
15
16
        /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
17
        $sm = $this->_conn->getSchemaManager();
18
        $sm->createTable($table);
19
20
        $this->_conn->insert('autoincremented_table', ['test_int' => 1]);
21
        $this->_conn->insert('autoincremented_table', ['test_int' => 2]);
22
        $this->_conn->insert('autoincremented_table', ['test_int' => 3]);
23
24
        $lastId = $this->getIdByTestInt(3);
25
26
        $this->assertEquals(3, $lastId);
27
28
        $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('autoincremented_table'));
29
30
        $this->_conn->insert('autoincremented_table', ['test_int' => 4]);
31
        $lastId = $this->getIdByTestInt(4);
32
        $this->assertEquals(1, $lastId);
33
    }
34
35
    protected function getIdByTestInt(int $whereTestInt)
36
    {
37
        $row = $this->_conn->fetchAssoc('SELECT id FROM autoincremented_table WHERE test_int = ?', [$whereTestInt]);
38
        $row = array_change_key_case($row, CASE_LOWER);
0 ignored issues
show
Bug introduced by
It seems like $row can also be of type boolean; 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

38
        $row = array_change_key_case(/** @scrutinizer ignore-type */ $row, CASE_LOWER);
Loading history...
39
40
        return $row['id'];
41
    }
42
}
43