Passed
Pull Request — master (#3206)
by Ilya
12:43
created

ResetAutoincrementTest::getIdByTestInt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

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