Skip to content

Commit 3bbdbf1

Browse files
committed
wip
1 parent c3276c8 commit 3bbdbf1

5 files changed

Lines changed: 396 additions & 217 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class WP_MySQL_On_SQLite_PDO_API_Tests extends TestCase {
6+
/** @var WP_MySQL_On_SQLite */
7+
private $driver;
8+
9+
public function setUp(): void {
10+
$this->driver = new WP_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=WordPress;' );
11+
}
12+
13+
public function test_connection(): void {
14+
$driver = new WP_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=WordPress;' );
15+
$this->assertInstanceOf( PDO::class, $driver );
16+
}
17+
18+
public function test_query(): void {
19+
$result = $this->driver->query( 'SELECT 1' );
20+
$this->assertInstanceOf( PDOStatement::class, $result );
21+
$this->assertEquals( 1, $result->fetchColumn() );
22+
}
23+
24+
public function test_begin_transaction(): void {
25+
$result = $this->driver->beginTransaction();
26+
$this->assertTrue( $result );
27+
}
28+
29+
public function test_begin_transaction_already_active(): void {
30+
$this->driver->beginTransaction();
31+
32+
$this->expectException( PDOException::class );
33+
$this->expectExceptionMessage( 'There is already an active transaction' );
34+
$this->expectExceptionCode( 0 );
35+
$this->driver->beginTransaction();
36+
}
37+
38+
public function test_commit(): void {
39+
$this->driver->beginTransaction();
40+
$result = $this->driver->commit();
41+
$this->assertTrue( $result );
42+
}
43+
44+
public function test_commit_no_active_transaction(): void {
45+
$this->expectException( PDOException::class );
46+
$this->expectExceptionMessage( 'There is no active transaction' );
47+
$this->expectExceptionCode( 0 );
48+
$this->driver->commit();
49+
}
50+
51+
public function test_rollback(): void {
52+
$this->driver->beginTransaction();
53+
$result = $this->driver->rollBack();
54+
$this->assertTrue( $result );
55+
}
56+
57+
public function test_rollback_no_active_transaction(): void {
58+
$this->expectException( PDOException::class );
59+
$this->expectExceptionMessage( 'There is no active transaction' );
60+
$this->expectExceptionCode( 0 );
61+
$this->driver->rollBack();
62+
}
63+
}

0 commit comments

Comments
 (0)