Passed
Pull Request — master (#3206)
by Ilya
64:04
created

ResetAutoincrementTest::getIdByTestInt()   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 1
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Functional;
4
5
use Doctrine\DBAL\Schema\Table;
6
use Doctrine\Tests\DbalFunctionalTestCase;
7
8
class ResetAutoincrementTest extends 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
        $sm = $this->connection->getSchemaManager();
18
        $sm->createTable($table);
19
20
        $this->connection->insert('autoincremented_table', ['test_int' => 1]);
21
        $this->connection->insert('autoincremented_table', ['test_int' => 2]);
22
        $this->connection->insert('autoincremented_table', ['test_int' => 3]);
23
24
        $lastId = $this->getIdByTestInt(3);
25
26
        $this->assertEquals(3, $lastId);
27
28
        $this->connection->exec($this->connection->getDatabasePlatform()->getTruncateTableSQL('autoincremented_table'));
29
30
        $this->connection->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
        return $this->connection->fetchColumn('SELECT id FROM autoincremented_table WHERE test_int = ?', [$whereTestInt]);
38
    }
39
}
40