|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gember\RdbmsEventStoreDoctrineDbal\Test\Saga; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\DriverManager; |
|
8
|
|
|
use Doctrine\DBAL\Tools\DsnParser; |
|
9
|
|
|
use Gember\DependencyContracts\EventStore\Saga\RdbmsSagaNotFoundException; |
|
10
|
|
|
use Gember\RdbmsEventStoreDoctrineDbal\Saga\DoctrineDbalRdbmsSagaFactory; |
|
|
|
|
|
|
11
|
|
|
use Gember\RdbmsEventStoreDoctrineDbal\Saga\DoctrineRdbmsSagaStoreRepository; |
|
|
|
|
|
|
12
|
|
|
use Gember\RdbmsEventStoreDoctrineDbal\Saga\TableSchema\SagaTableSchemaFactory; |
|
|
|
|
|
|
13
|
|
|
use Gember\RdbmsEventStoreDoctrineDbal\Test\TestDoubles\TestIdentityGenerator; |
|
14
|
|
|
use PHPUnit\Framework\Attributes\Test; |
|
|
|
|
|
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
use Override; |
|
|
|
|
|
|
17
|
|
|
use DateTimeImmutable; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @internal |
|
21
|
|
|
*/ |
|
22
|
|
|
final class DoctrineRdbmsSagaStoreRepositoryTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
private DoctrineRdbmsSagaStoreRepository $repository; |
|
25
|
|
|
private TestIdentityGenerator $identityGenerator; |
|
26
|
|
|
|
|
27
|
|
|
#[Override] |
|
28
|
|
|
protected function setUp(): void |
|
29
|
|
|
{ |
|
30
|
|
|
parent::setUp(); |
|
31
|
|
|
|
|
32
|
|
|
$connection = DriverManager::getConnection((new DsnParser())->parse('pdo-sqlite:///:memory:')); |
|
33
|
|
|
$connection->executeStatement((string) file_get_contents(__DIR__ . '/../schema.sql')); |
|
34
|
|
|
|
|
35
|
|
|
$this->repository = new DoctrineRdbmsSagaStoreRepository( |
|
36
|
|
|
$connection, |
|
37
|
|
|
SagaTableSchemaFactory::createDefaultSagaStore(), |
|
38
|
|
|
SagaTableSchemaFactory::createDefaultSagaStoreRelation(), |
|
39
|
|
|
new DoctrineDbalRdbmsSagaFactory(), |
|
40
|
|
|
$this->identityGenerator = new TestIdentityGenerator(), |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
#[Test] |
|
45
|
|
|
public function itShouldThrowExceptionWhenSagaNotFound(): void |
|
46
|
|
|
{ |
|
47
|
|
|
self::expectException(RdbmsSagaNotFoundException::class); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$this->repository->get('some.saga', '01K76GDQ5RT71G7HQVNR264KD4'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
#[Test] |
|
53
|
|
|
public function itShouldSaveAndGetSaga(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->identityGenerator->ids[] = '01K7Q083CX4T7Z0NT5CKEX8NEJ'; |
|
56
|
|
|
|
|
57
|
|
|
$this->repository->save( |
|
58
|
|
|
'some.saga', |
|
59
|
|
|
'{"some":"data"}', |
|
60
|
|
|
new DateTimeImmutable('2025-10-10 12:00:34'), |
|
61
|
|
|
'01K76GDQ5RT71G7HQVNR264KD4', |
|
62
|
|
|
'01K7Q033P5174AXA054FFAHW2F', |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$saga = $this->repository->get('some.saga', '01K76GDQ5RT71G7HQVNR264KD4'); |
|
66
|
|
|
|
|
67
|
|
|
self::assertSame('01K7Q083CX4T7Z0NT5CKEX8NEJ', $saga->id); |
|
68
|
|
|
self::assertSame('some.saga', $saga->sagaName); |
|
69
|
|
|
self::assertSame(['01K76GDQ5RT71G7HQVNR264KD4', '01K7Q033P5174AXA054FFAHW2F'], $saga->sagaIds); |
|
70
|
|
|
self::assertSame('{"some":"data"}', $saga->payload); |
|
71
|
|
|
self::assertEquals(new DateTimeImmutable('2025-10-10 12:00:34'), $saga->createdAt); |
|
72
|
|
|
self::assertNull($saga->updatedAt); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
#[Test] |
|
76
|
|
|
public function itShouldSaveExistingSaga(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$this->identityGenerator->ids[] = '01K7Q083CX4T7Z0NT5CKEX8NEJ'; |
|
79
|
|
|
|
|
80
|
|
|
$this->repository->save( |
|
81
|
|
|
'some.saga', |
|
82
|
|
|
'{"some":"data"}', |
|
83
|
|
|
new DateTimeImmutable('2025-10-10 12:00:34'), |
|
84
|
|
|
'01K76GDQ5RT71G7HQVNR264KD4', |
|
85
|
|
|
'01K7Q0GR8ABHBZG8QCGTXJXJ7T', |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$this->repository->save( |
|
89
|
|
|
'some.saga', |
|
90
|
|
|
'{"some":"updated"}', |
|
91
|
|
|
new DateTimeImmutable('2025-10-10 13:30:12'), |
|
92
|
|
|
'01K76GDQ5RT71G7HQVNR264KD4', |
|
93
|
|
|
'01K7Q0JGY9ZMX11K75AAY5J78R', |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
$saga = $this->repository->get('some.saga', '01K76GDQ5RT71G7HQVNR264KD4'); |
|
97
|
|
|
|
|
98
|
|
|
self::assertSame('01K7Q083CX4T7Z0NT5CKEX8NEJ', $saga->id); |
|
99
|
|
|
self::assertSame('some.saga', $saga->sagaName); |
|
100
|
|
|
self::assertSame(['01K76GDQ5RT71G7HQVNR264KD4', '01K7Q0JGY9ZMX11K75AAY5J78R'], $saga->sagaIds); |
|
101
|
|
|
self::assertSame('{"some":"updated"}', $saga->payload); |
|
102
|
|
|
self::assertEquals(new DateTimeImmutable('2025-10-10 12:00:34'), $saga->createdAt); |
|
103
|
|
|
self::assertEquals(new DateTimeImmutable('2025-10-10 13:30:12'), $saga->updatedAt); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
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