-
-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathGenericDatabaseTest.php
More file actions
84 lines (71 loc) · 2.38 KB
/
GenericDatabaseTest.php
File metadata and controls
84 lines (71 loc) · 2.38 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
namespace Tempest\Database\Tests;
use Exception;
use PHPUnit\Framework\TestCase;
use Tempest\Container\GenericContainer;
use Tempest\Database\Connection\Connection;
use Tempest\Database\GenericDatabase;
use Tempest\Database\Transactions\GenericTransactionManager;
use Tempest\EventBus\EventBusConfig;
use Tempest\EventBus\GenericEventBus;
use Tempest\EventBus\Testing\FakeEventBus;
use Tempest\Mapper\SerializerFactory;
/**
* @internal
*/
final class GenericDatabaseTest extends TestCase
{
public function test_it_executes_transactions(): void
{
$connection = $this->createMock(Connection::class);
$connection
->expects($this->once())
->method('beginTransaction')
->withAnyParameters()
->willReturn(true);
$connection
->expects($this->once())
->method('commit')
->withAnyParameters()
->willReturn(true);
$container = new GenericContainer();
$eventBus = new FakeEventBus(new GenericEventBus($container, new EventBusConfig()));
$database = new GenericDatabase(
$connection,
new GenericTransactionManager($connection),
new SerializerFactory(new GenericContainer()),
$eventBus,
);
$result = $database->withinTransaction(function () {
return true;
});
$this->assertTrue($result);
}
public function test_it_rolls_back_transactions_on_failure(): void
{
$connection = $this->createMock(Connection::class);
$connection
->expects($this->once())
->method('beginTransaction')
->withAnyParameters()
->willReturn(true);
$connection
->expects($this->once())
->method('rollback')
->withAnyParameters()
->willReturn(true);
$container = new GenericContainer();
$eventBus = new FakeEventBus(new GenericEventBus($container, new EventBusConfig()));
$database = new GenericDatabase(
$connection,
new GenericTransactionManager($connection),
new SerializerFactory(new GenericContainer()),
$eventBus,
);
$result = $database->withinTransaction(function (): never {
throw new Exception();
});
$this->assertFalse($result);
}
}