|
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
|
|
|
|