|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gember\RdbmsEventStoreDoctrineDbal\Test; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\DriverManager; |
|
8
|
|
|
use Doctrine\DBAL\Tools\DsnParser; |
|
9
|
|
|
use Gember\DependencyContracts\EventStore\Rdbms\RdbmsEvent; |
|
10
|
|
|
use Gember\RdbmsEventStoreDoctrineDbal\DoctrineDbalRdbmsEventFactory; |
|
|
|
|
|
|
11
|
|
|
use Gember\RdbmsEventStoreDoctrineDbal\DoctrineDbalRdbmsEventStoreRepository; |
|
|
|
|
|
|
12
|
|
|
use Gember\RdbmsEventStoreDoctrineDbal\TableSchema\TableSchemaFactory; |
|
|
|
|
|
|
13
|
|
|
use PHPUnit\Framework\Attributes\Test; |
|
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Override; |
|
|
|
|
|
|
16
|
|
|
use DateTimeImmutable; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @internal |
|
20
|
|
|
*/ |
|
21
|
|
|
final class DoctrineDbalRdbmsEventStoreRepositoryTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
private DoctrineDbalRdbmsEventStoreRepository $repository; |
|
24
|
|
|
|
|
25
|
|
|
#[Override] |
|
26
|
|
|
protected function setUp(): void |
|
27
|
|
|
{ |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
|
|
30
|
|
|
$connection = DriverManager::getConnection((new DsnParser())->parse('pdo-sqlite:///:memory:')); |
|
31
|
|
|
$connection->executeStatement((string) file_get_contents(__DIR__ . '/schema.sql')); |
|
32
|
|
|
|
|
33
|
|
|
$this->repository = new DoctrineDbalRdbmsEventStoreRepository( |
|
34
|
|
|
$connection, |
|
35
|
|
|
TableSchemaFactory::createDefaultEventStore(), |
|
36
|
|
|
TableSchemaFactory::createDefaultEventStoreRelation(), |
|
37
|
|
|
new DoctrineDbalRdbmsEventFactory(), |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
$this->repository->saveEvents([ |
|
41
|
|
|
new RdbmsEvent( |
|
42
|
|
|
'63129dc3-4a27-4242-a8bc-6f79636a6fa9', |
|
43
|
|
|
['6ae07469-0f43-4f33-979b-c783b6824ce0', '0c1ff409-a4be-42f1-90dd-5d7b0130a426'], |
|
44
|
|
|
'event_name', |
|
45
|
|
|
'{"data":"some"}', |
|
46
|
|
|
['metadata' => 'some'], |
|
47
|
|
|
new DateTimeImmutable('2024-12-06 12:05:04.456344'), |
|
48
|
|
|
), |
|
49
|
|
|
new RdbmsEvent( |
|
50
|
|
|
'707678d3-c91d-4864-9729-555b22496853', |
|
51
|
|
|
['0e76f2bd-2aae-44a4-b149-740c080e4d05'], |
|
52
|
|
|
'event_name', |
|
53
|
|
|
'{"data":"another_event"}', |
|
54
|
|
|
['metadata' => 'another_event'], |
|
55
|
|
|
new DateTimeImmutable('2024-12-01 13:16:24.467784'), |
|
56
|
|
|
), |
|
57
|
|
|
new RdbmsEvent( |
|
58
|
|
|
'7ac51abe-9176-4794-8246-24b75c2ba914', |
|
59
|
|
|
['0c1ff409-a4be-42f1-90dd-5d7b0130a426'], |
|
60
|
|
|
'event_name_2', |
|
61
|
|
|
'{"data":"another"}', |
|
62
|
|
|
['metadata' => 'another'], |
|
63
|
|
|
new DateTimeImmutable('2024-12-04 13:15:26.755844'), |
|
64
|
|
|
), |
|
65
|
|
|
new RdbmsEvent( |
|
66
|
|
|
'd404e3c1-c782-4115-b8ec-d8cb341d87cb', |
|
67
|
|
|
['6ae07469-0f43-4f33-979b-c783b6824ce0'], |
|
68
|
|
|
'event_name_3', |
|
69
|
|
|
'{"data":"another"}', |
|
70
|
|
|
['metadata' => 'another3'], |
|
71
|
|
|
new DateTimeImmutable('2024-12-02 13:16:24.467784'), |
|
72
|
|
|
), |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
#[Test] |
|
77
|
|
|
public function itShouldGetEvents(): void |
|
78
|
|
|
{ |
|
79
|
|
|
$events = $this->repository->getEvents( |
|
80
|
|
|
[ |
|
81
|
|
|
'0c1ff409-a4be-42f1-90dd-5d7b0130a426', |
|
82
|
|
|
'6ae07469-0f43-4f33-979b-c783b6824ce0', |
|
83
|
|
|
], |
|
84
|
|
|
[ |
|
85
|
|
|
'event_name', |
|
86
|
|
|
'event_name_2', |
|
87
|
|
|
], |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
self::assertEquals([ |
|
91
|
|
|
new RdbmsEvent( |
|
92
|
|
|
'7ac51abe-9176-4794-8246-24b75c2ba914', |
|
93
|
|
|
[ |
|
94
|
|
|
'0c1ff409-a4be-42f1-90dd-5d7b0130a426', |
|
95
|
|
|
], |
|
96
|
|
|
'event_name_2', |
|
97
|
|
|
'{"data":"another"}', |
|
98
|
|
|
['metadata' => 'another'], |
|
99
|
|
|
new DateTimeImmutable('2024-12-04 13:15:26.755844'), |
|
100
|
|
|
), |
|
101
|
|
|
new RdbmsEvent( |
|
102
|
|
|
'63129dc3-4a27-4242-a8bc-6f79636a6fa9', |
|
103
|
|
|
[ |
|
104
|
|
|
'0c1ff409-a4be-42f1-90dd-5d7b0130a426', |
|
105
|
|
|
'6ae07469-0f43-4f33-979b-c783b6824ce0', |
|
106
|
|
|
], |
|
107
|
|
|
'event_name', |
|
108
|
|
|
'{"data":"some"}', |
|
109
|
|
|
['metadata' => 'some'], |
|
110
|
|
|
new DateTimeImmutable('2024-12-06 12:05:04.456344'), |
|
111
|
|
|
), |
|
112
|
|
|
], $events); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
#[Test] |
|
116
|
|
|
public function itShouldReturnNullWhenGetLastEventIdPersistedIsNotFound(): void |
|
117
|
|
|
{ |
|
118
|
|
|
$lastEventIdPersisted = $this->repository->getLastEventIdPersisted( |
|
119
|
|
|
[ |
|
120
|
|
|
'072fd355-bd4e-423b-a7ba-fb1a77e32d7c', |
|
121
|
|
|
'60a8635c-c769-4d19-8cae-a9571401848f', |
|
122
|
|
|
], |
|
123
|
|
|
[ |
|
124
|
|
|
'event_name', |
|
125
|
|
|
'event_name_2', |
|
126
|
|
|
], |
|
127
|
|
|
); |
|
128
|
|
|
|
|
129
|
|
|
self::assertNull($lastEventIdPersisted); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
#[Test] |
|
133
|
|
|
public function itShouldGetLastEventIdPersisted(): void |
|
134
|
|
|
{ |
|
135
|
|
|
$lastEventIdPersisted = $this->repository->getLastEventIdPersisted( |
|
136
|
|
|
[ |
|
137
|
|
|
'0c1ff409-a4be-42f1-90dd-5d7b0130a426', |
|
138
|
|
|
'6ae07469-0f43-4f33-979b-c783b6824ce0', |
|
139
|
|
|
], |
|
140
|
|
|
[ |
|
141
|
|
|
'event_name', |
|
142
|
|
|
'event_name_2', |
|
143
|
|
|
], |
|
144
|
|
|
); |
|
145
|
|
|
|
|
146
|
|
|
self::assertSame('63129dc3-4a27-4242-a8bc-6f79636a6fa9', $lastEventIdPersisted); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths