-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoctrineTransactionalMessageRepositoryTest.php
79 lines (64 loc) · 2.46 KB
/
DoctrineTransactionalMessageRepositoryTest.php
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
<?php
namespace EventSauce\MessageOutbox\DoctrineOutbox;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\DriverManager;
use EventSauce\EventSourcing\AggregateRootId;
use EventSauce\EventSourcing\MessageRepository;
use EventSauce\EventSourcing\Serialization\ConstructingMessageSerializer;
use EventSauce\MessageOutbox\OutboxRepository;
use EventSauce\MessageOutbox\TestTooling\DoctrineConnectionTrait;
use EventSauce\MessageOutbox\TestTooling\TransactionalMessageRepositoryTestCase;
use EventSauce\MessageRepository\DoctrineMessageRepository\DoctrineUuidV4MessageRepository;
use EventSauce\MessageRepository\DoctrineMessageRepository\DummyAggregateRootId;
use function getenv;
use function interface_exists;
class DoctrineTransactionalMessageRepositoryTest extends TransactionalMessageRepositoryTestCase
{
use DoctrineConnectionTrait;
private Connection $connection;
protected function setUp(): void
{
if (interface_exists(ResultStatement::class)) {
$this->markTestSkipped('Doctrine v2 installed');
}
parent::setUp();
$this->connection = DriverManager::getConnection($this->getConnectionParams());
$this->connection->executeQuery('TRUNCATE TABLE '.$this->repositoryTable);
$this->connection->executeQuery('TRUNCATE TABLE '.$this->outboxTable);
}
protected function formatDsn(): string
{
$host = getenv('EVENTSAUCE_TESTING_MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('EVENTSAUCE_TESTING_MYSQL_PORT') ?: '3306';
return "mysql://username:password@$host:$port/outbox_messages";
}
protected function messageRepository(): MessageRepository
{
return new DoctrineUuidV4MessageRepository(
$this->connection,
$this->repositoryTable,
new ConstructingMessageSerializer(),
);
}
protected function outboxRepository(): OutboxRepository
{
return new DoctrineOutboxRepository(
$this->connection,
$this->outboxTable,
new ConstructingMessageSerializer(),
);
}
protected function transactionalRepository(): MessageRepository
{
return new DoctrineTransactionalMessageRepository(
$this->connection,
$this->messageRepository(),
$this->outboxRepository(),
);
}
protected function aggregateRootId(): AggregateRootId
{
return DummyAggregateRootId::generate();
}
}