DoctrineRdbmsSagaStoreRepositoryTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
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 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...
14
use PHPUnit\Framework\TestCase;
15
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...
16
use DateTimeImmutable;
17
18
/**
19
 * @internal
20
 */
21
final class DoctrineRdbmsSagaStoreRepositoryTest extends TestCase
22
{
23
    private DoctrineRdbmsSagaStoreRepository $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 DoctrineRdbmsSagaStoreRepository(
34
            $connection,
35
            SagaTableSchemaFactory::createDefaultSagaStore(),
36
            new DoctrineDbalRdbmsSagaFactory(),
37
        );
38
    }
39
40
    #[Test]
41
    public function itShouldThrowExceptionWhenSagaNotFound(): void
42
    {
43
        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

43
        self::/** @scrutinizer ignore-call */ 
44
              expectException(RdbmsSagaNotFoundException::class);
Loading history...
44
45
        $this->repository->get('some.saga', '01K76GDQ5RT71G7HQVNR264KD4');
46
    }
47
48
    #[Test]
49
    public function itShouldSaveAndGetSaga(): void
50
    {
51
        $this->repository->save(
52
            'some.saga',
53
            '01K76GDQ5RT71G7HQVNR264KD4',
54
            '{"some":"data"}',
55
            new DateTimeImmutable('2025-10-10 12:00:34'),
56
        );
57
58
        $saga = $this->repository->get('some.saga', '01K76GDQ5RT71G7HQVNR264KD4');
59
60
        self::assertSame('some.saga', $saga->sagaName);
61
        self::assertSame('01K76GDQ5RT71G7HQVNR264KD4', $saga->sagaId);
62
        self::assertSame('{"some":"data"}', $saga->payload);
63
        self::assertEquals(new DateTimeImmutable('2025-10-10 12:00:34'), $saga->createdAt);
64
        self::assertNull($saga->updatedAt);
65
    }
66
67
    #[Test]
68
    public function itShouldSaveExistingSaga(): void
69
    {
70
        $this->repository->save(
71
            'some.saga',
72
            '01K76GDQ5RT71G7HQVNR264KD4',
73
            '{"some":"data"}',
74
            new DateTimeImmutable('2025-10-10 12:00:34'),
75
        );
76
77
        $this->repository->save(
78
            'some.saga',
79
            '01K76GDQ5RT71G7HQVNR264KD4',
80
            '{"some":"updated"}',
81
            new DateTimeImmutable('2025-10-10 13:30:12'),
82
        );
83
84
        $saga = $this->repository->get('some.saga', '01K76GDQ5RT71G7HQVNR264KD4');
85
86
        self::assertSame('some.saga', $saga->sagaName);
87
        self::assertSame('01K76GDQ5RT71G7HQVNR264KD4', $saga->sagaId);
88
        self::assertSame('{"some":"updated"}', $saga->payload);
89
        self::assertEquals(new DateTimeImmutable('2025-10-10 12:00:34'), $saga->createdAt);
90
        self::assertEquals(new DateTimeImmutable('2025-10-10 13:30:12'), $saga->updatedAt);
91
    }
92
}
93