Failed Conditions
Pull Request — master (#3544)
by Luís
19:33 queued 08:11
created

autoIncrementIdsShouldBeFetched()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Doctrine\Tests\DBAL\Functional;
5
6
use Doctrine\DBAL\DriverManager;
7
use PDO;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * @group GH-3487
12
 */
13
final class WrappedPDOConnectionTest extends TestCase
14
{
15
    /** @var PDO */
16
    private $pdo;
17
18
    /**
19
     * @before
20
     */
21
    public function createInMemoryConnection() : void
22
    {
23
        $this->pdo = new PDO('sqlite::memory:');
24
    }
25
26
    /**
27
     * @test
28
     */
29
    public function queriesAndPreparedStatementsShouldWork() : void
30
    {
31
        $connection = DriverManager::getConnection(['pdo' => $this->pdo]);
32
33
        self::assertTrue($connection->ping());
34
35
        $connection->query('CREATE TABLE testing (id INTEGER NOT NULL PRIMARY KEY)');
36
        $connection->query('INSERT INTO testing VALUES (1), (2), (3)');
37
38
        $statement = $connection->prepare('SELECT id FROM testing WHERE id >= ?');
39
        $statement->execute([2]);
40
41
        self::assertSame([['id' => '2'], ['id' => '3']], $statement->fetchAll(PDO::FETCH_ASSOC));
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function autoIncrementIdsShouldBeFetched() : void
48
    {
49
        $connection = DriverManager::getConnection(['pdo' => $this->pdo]);
50
51
        $connection->query('CREATE TABLE testing (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(10) NOT NULL)');
52
        $connection->query('INSERT INTO testing (name) VALUES ("Testing")');
53
54
        self::assertSame('1', $connection->lastInsertId());
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function transactionControlShouldHappenNormally() : void
61
    {
62
        $connection = DriverManager::getConnection(['pdo' => $this->pdo]);
63
        $connection->query('CREATE TABLE testing (id INTEGER NOT NULL PRIMARY KEY)');
64
65
        $connection->beginTransaction();
66
        $connection->query('INSERT INTO testing VALUES (1), (2), (3)');
67
        $connection->rollBack();
68
69
        self::assertSame([], $connection->fetchAll('SELECT * FROM testing'));
70
    }
71
}
72