DoctrineRdbmsSagaStoreRepositoryTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A itShouldSaveExistingSaga() 0 29 1
A itShouldSaveAndGetSaga() 0 21 1
A itShouldThrowExceptionWhenSagaNotFound() 0 6 1
A setUp() 0 14 1
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;
0 ignored issues
show
Bug introduced by
The type Gember\RdbmsEventStoreDo...ineDbalRdbmsSagaFactory was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Gember\RdbmsEventStoreDoctrineDbal\Saga\DoctrineRdbmsSagaStoreRepository;
0 ignored issues
show
Bug introduced by
The type Gember\RdbmsEventStoreDo...dbmsSagaStoreRepository was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Gember\RdbmsEventStoreDoctrineDbal\Saga\TableSchema\SagaTableSchemaFactory;
0 ignored issues
show
Bug introduced by
The type Gember\RdbmsEventStoreDo...\SagaTableSchemaFactory was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Gember\RdbmsEventStoreDoctrineDbal\Test\TestDoubles\TestIdentityGenerator;
14
use PHPUnit\Framework\Attributes\Test;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Attributes\Test was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use PHPUnit\Framework\TestCase;
16
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        self::/** @scrutinizer ignore-call */ 
48
              expectException(RdbmsSagaNotFoundException::class);
Loading history...
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