-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionTest.php
More file actions
51 lines (39 loc) · 1.11 KB
/
TransactionTest.php
File metadata and controls
51 lines (39 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace ModernPDO\Tests\Unit;
use ModernPDO\Transaction;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function PHPUnit\Framework\assertTrue;
class TransactionTest extends TestCase
{
private function make(): Transaction
{
/** @var MockObject&\PDO */
$pdo = $this->createMock(\PDO::class);
$pdo
->expects(self::once())
->method('beginTransaction')
->willReturn(true);
$pdo
->expects(self::once())
->method('inTransaction')
->willReturn(true);
$pdo->method('commit')->willReturn(true);
$pdo->method('rollBack')->willReturn(true);
return new Transaction($pdo);
}
public function testCommit(): void
{
$tr = $this->make();
assertTrue($tr->begin());
assertTrue($tr->isActive());
assertTrue($tr->commit());
}
public function testRollback(): void
{
$tr = $this->make();
assertTrue($tr->begin());
assertTrue($tr->isActive());
assertTrue($tr->rollBack());
}
}