Skip to content

Commit

Permalink
Update SA tools, fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBadura committed Feb 7, 2024
1 parent 848c9c1 commit 7e76aef
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 46 deletions.
30 changes: 5 additions & 25 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
<code><![CDATA[$method->getName()]]></code>
</MixedMethodCall>
</file>
<file src="src/EventBus/Message.php">
<InvalidReturnStatement>
<code>$headers</code>
</InvalidReturnStatement>
<InvalidReturnType>
<code>Headers</code>
</InvalidReturnType>
</file>
<file src="src/EventBus/Serializer/EventSerializerMessageSerializer.php">
<MixedArgumentTypeCoercion>
<code><![CDATA[$data['headers']]]></code>
Expand Down Expand Up @@ -104,6 +96,11 @@
<code>$index</code>
</InvalidPropertyAssignmentValue>
</file>
<file src="src/Store/DoctrineDbalStoreStream.php">
<ArgumentTypeCoercion>
<code><![CDATA[DoctrineHelper::normalizeCustomHeaders($data['custom_headers'], $platform)]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Store/DoctrineHelper.php">
<MixedReturnTypeCoercion>
<code>$normalizedCustomHeaders</code>
Expand Down Expand Up @@ -193,23 +190,6 @@
<code>$name</code>
</PropertyNotSetInConstructor>
</file>
<file src="tests/Unit/EventBus/MessageTest.php">
<InvalidArgument>
<code><![CDATA[[
'foo' => 'bar',
'aggregateName' => 'profile',
'aggregateId' => '1',
'playhead' => 3,
'recordedOn' => $recordedAt,
'newStreamStart' => true,
'archived' => true,
]]]></code>
</InvalidArgument>
<TypeDoesNotContainType>
<code>assertSame</code>
<code>assertSame</code>
</TypeDoesNotContainType>
</file>
<file src="tests/Unit/Fixture/MessageNormalizer.php">
<MixedArgumentTypeCoercion>
<code>$value</code>
Expand Down
7 changes: 6 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
path: src/Console/DoctrineHelper.php

-
message: "#^Method Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message\\:\\:headers\\(\\) should return array\\{aggregateName\\?\\: string, aggregateId\\?\\: string, playhead\\?\\: int\\<1, max\\>, recordedOn\\?\\: DateTimeImmutable, newStreamStart\\?\\: bool, archived\\?\\: bool\\} but returns non\\-empty\\-array\\<string, mixed\\>\\.$#"
message: "#^Property Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message\\<T of object\\>\\:\\:\\$headers \\(array\\{aggregateName\\?\\: string, aggregateId\\?\\: string, playhead\\?\\: int\\<1, max\\>, recordedOn\\?\\: DateTimeImmutable, newStreamStart\\?\\: bool, archived\\?\\: bool\\}\\) does not accept non\\-empty\\-array\\<string, mixed\\>\\.$#"
count: 1
path: src/EventBus/Message.php

Expand Down Expand Up @@ -35,6 +35,11 @@ parameters:
count: 1
path: src/Store/ArrayStream.php

-
message: "#^Parameter \\#1 \\$headers of method Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message\\<object\\>\\:\\:withHeaders\\(\\) expects array\\{aggregateName\\?\\: string, aggregateId\\?\\: string, playhead\\?\\: int\\<1, max\\>, recordedOn\\?\\: DateTimeImmutable, newStreamStart\\?\\: bool, archived\\?\\: bool\\}, array\\<string, mixed\\> given\\.$#"
count: 1
path: src/Store/DoctrineDbalStoreStream.php

-
message: "#^Ternary operator condition is always true\\.$#"
count: 1
Expand Down
9 changes: 9 additions & 0 deletions src/EventBus/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
* archived?: bool,
* ...<string, mixed>
* }
*
* @phpstan-type Headers = array{
* aggregateName?: string,
* aggregateId?: string,
* playhead?: positive-int,
* recordedOn?: DateTimeImmutable,
* newStreamStart?: bool,
* archived?: bool
* }
*/
final class Message
{
Expand Down
2 changes: 1 addition & 1 deletion src/Outbox/DoctrineOutboxStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function configureSchema(Schema $schema, Connection $connection): void
private function extractId(Message $message): int
{
try {
$value = $message->customHeader(self::HEADER_OUTBOX_IDENTIFIER);
$value = $message->header(self::HEADER_OUTBOX_IDENTIFIER);
} catch (HeaderNotFound) {
throw OutboxHeaderIssue::missingHeader(self::HEADER_OUTBOX_IDENTIFIER);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Store/DoctrineDbalStoreStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function buildGenerator(
EventSerializer $serializer,
AbstractPlatform $platform,
): Generator {
/** @var array{id: positive-int, aggregate: string, aggregate_id: string, playhead: int|string, event: string, payload: string, recorded_on: string, custom_headers: string} $data */
/** @var array{id: positive-int, aggregate: string, aggregate_id: string, playhead: int|string, event: string, payload: string, recorded_on: string, archived: int|string, new_stream_start: int|string, custom_headers: string} $data */
foreach ($result->iterateAssociative() as $data) {
if ($this->position === null) {
$this->position = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/Store/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

use function dd;
use function is_array;
use function is_bool;
use function is_int;

final class DoctrineHelper
Expand Down
12 changes: 9 additions & 3 deletions tests/Integration/Store/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ public function testSave(): void
->withAggregateName('profile')
->withAggregateId('test')
->withPlayhead(1)
->withRecordedOn(new DateTimeImmutable('2020-01-01 00:00:00')),
->withRecordedOn(new DateTimeImmutable('2020-01-01 00:00:00'))
->withArchived(false)
->withNewStreamStart(false),
Message::create(new ProfileCreated(ProfileId::fromString('test'), 'test'))
->withAggregateName('profile')
->withAggregateId('test')
->withPlayhead(2)
->withRecordedOn(new DateTimeImmutable('2020-01-02 00:00:00')),
->withRecordedOn(new DateTimeImmutable('2020-01-02 00:00:00'))
->withArchived(false)
->withNewStreamStart(false),
];

$this->store->save(...$messages);
Expand Down Expand Up @@ -93,7 +97,9 @@ public function testLoad(): void
->withAggregateName('profile')
->withAggregateId('test')
->withPlayhead(1)
->withRecordedOn(new DateTimeImmutable('2020-01-01 00:00:00'));
->withRecordedOn(new DateTimeImmutable('2020-01-01 00:00:00'))
->withArchived(false)
->withNewStreamStart(false);

$this->store->save($message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testSerialize(): void

$content = $serializer->serialize($message);

self::assertEquals('YToyOntzOjE1OiJzZXJpYWxpemVkRXZlbnQiO086NTE6IlBhdGNobGV2ZWxcRXZlbnRTb3VyY2luZ1xTZXJpYWxpemVyXFNlcmlhbGl6ZWRFdmVudCI6Mjp7czo0OiJuYW1lIjtzOjE1OiJwcm9maWxlX3Zpc2l0ZWQiO3M6NzoicGF5bG9hZCI7czo5OiJ7aWQ6IGZvb30iO31zOjc6ImhlYWRlcnMiO2E6Mzp7czoxMDoicmVjb3JkZWRPbiI7TzoxNzoiRGF0ZVRpbWVJbW11dGFibGUiOjM6e3M6NDoiZGF0ZSI7czoyNjoiMjAyMC0wMS0wMSAyMDowMDowMC4wMDAwMDAiO3M6MTM6InRpbWV6b25lX3R5cGUiO2k6MTtzOjg6InRpbWV6b25lIjtzOjY6IiswMTowMCI7fXM6MTQ6Im5ld1N0cmVhbVN0YXJ0IjtiOjA7czo4OiJhcmNoaXZlZCI7YjowO319', $content);
self::assertEquals('YToyOntzOjE1OiJzZXJpYWxpemVkRXZlbnQiO086NTE6IlBhdGNobGV2ZWxcRXZlbnRTb3VyY2luZ1xTZXJpYWxpemVyXFNlcmlhbGl6ZWRFdmVudCI6Mjp7czo0OiJuYW1lIjtzOjE1OiJwcm9maWxlX3Zpc2l0ZWQiO3M6NzoicGF5bG9hZCI7czo5OiJ7aWQ6IGZvb30iO31zOjc6ImhlYWRlcnMiO2E6MTp7czoxMDoicmVjb3JkZWRPbiI7TzoxNzoiRGF0ZVRpbWVJbW11dGFibGUiOjM6e3M6NDoiZGF0ZSI7czoyNjoiMjAyMC0wMS0wMSAyMDowMDowMC4wMDAwMDAiO3M6MTM6InRpbWV6b25lX3R5cGUiO2k6MTtzOjg6InRpbWV6b25lIjtzOjY6IiswMTowMCI7fX19', $content);
}

public function testDeserialize(): void
Expand Down
20 changes: 9 additions & 11 deletions tests/Unit/EventBus/Serializer/PhpNativeMessageSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,23 @@ public function testSerialize(): void

$content = $nativeSerializer->serialize($message);

self::assertEquals('Tzo0MToiUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UiOjg6e3M6NTY6IgBQYXRjaGxldmVsXEV2ZW50U291cmNpbmdcRXZlbnRCdXNcTWVzc2FnZQBhZ2dyZWdhdGVOYW1lIjtOO3M6NTQ6IgBQYXRjaGxldmVsXEV2ZW50U291cmNpbmdcRXZlbnRCdXNcTWVzc2FnZQBhZ2dyZWdhdGVJZCI7TjtzOjUxOiIAUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UAcGxheWhlYWQiO047czo1MzoiAFBhdGNobGV2ZWxcRXZlbnRTb3VyY2luZ1xFdmVudEJ1c1xNZXNzYWdlAHJlY29yZGVkT24iO086MTc6IkRhdGVUaW1lSW1tdXRhYmxlIjozOntzOjQ6ImRhdGUiO3M6MjY6IjIwMjAtMDEtMDEgMjA6MDA6MDAuMDAwMDAwIjtzOjEzOiJ0aW1lem9uZV90eXBlIjtpOjE7czo4OiJ0aW1lem9uZSI7czo2OiIrMDE6MDAiO31zOjU3OiIAUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UAbmV3U3RyZWFtU3RhcnQiO2I6MDtzOjUxOiIAUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UAYXJjaGl2ZWQiO2I6MDtzOjU2OiIAUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UA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sXEV2ZW50U291cmNpbmdcVGVzdHNcVW5pdFxGaXh0dXJlXFByb2ZpbGVJZABpZCI7czozOiJmb28iO319fQ==', $content);
}

public function testDeserialize(): void
{
$event = new ProfileVisited(
ProfileId::fromString('foo'),
);

$event = new ProfileVisited(ProfileId::fromString('foo'));
$nativeSerializer = new PhpNativeMessageSerializer();

$message = $nativeSerializer->deserialize('Tzo0MToiUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UiOjg6e3M6NTY6IgBQYXRjaGxldmVsXEV2ZW50U291cmNpbmdcRXZlbnRCdXNcTWVzc2FnZQBhZ2dyZWdhdGVOYW1lIjtOO3M6NTQ6IgBQYXRjaGxldmVsXEV2ZW50U291cmNpbmdcRXZlbnRCdXNcTWVzc2FnZQBhZ2dyZWdhdGVJZCI7TjtzOjUxOiIAUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UAcGxheWhlYWQiO047czo1MzoiAFBhdGNobGV2ZWxcRXZlbnRTb3VyY2luZ1xFdmVudEJ1c1xNZXNzYWdlAHJlY29yZGVkT24iO086MTc6IkRhdGVUaW1lSW1tdXRhYmxlIjozOntzOjQ6ImRhdGUiO3M6MjY6IjIwMjAtMDEtMDEgMjA6MDA6MDAuMDAwMDAwIjtzOjEzOiJ0aW1lem9uZV90eXBlIjtpOjE7czo4OiJ0aW1lem9uZSI7czo2OiIrMDE6MDAiO31zOjU3OiIAUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UAbmV3U3RyZWFtU3RhcnQiO2I6MDtzOjUxOiIAUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UAYXJjaGl2ZWQiO2I6MDtzOjU2OiIAUGF0Y2hsZXZlbFxFdmVudFNvdXJjaW5nXEV2ZW50QnVzXE1lc3NhZ2UAY3VzdG9tSGVhZGVycyI7YT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bmdcVGVzdHNcVW5pdFxGaXh0dXJlXFByb2ZpbGVJZABpZCI7czozOiJmb28iO319fQ==');

self::assertEquals($event, $message->event());
self::assertEquals([
'recordedOn' => new DateTimeImmutable('2020-01-01T20:00:00.000000+0100'),
'newStreamStart' => false,
'archived' => false,
], $message->headers());
self::assertEquals(
[
'recordedOn' => new DateTimeImmutable('2020-01-01T20:00:00.000000+0100'),
],
$message->headers(),
);
}

public function testDeserializeDecodeFailed(): void
Expand Down
8 changes: 5 additions & 3 deletions tests/Unit/Store/DoctrineDbalStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function testLoadWithOneEvent(): void
'event' => 'profile.created',
'payload' => '{"profileId": "1", "email": "s"}',
'recorded_on' => '2021-02-17 10:00:00',
'archived' => '0',
'new_stream_start' => '0',
'custom_headers' => '[]',
],
],
Expand All @@ -124,9 +126,9 @@ public function testLoadWithOneEvent(): void
$selectSqlBuilder->buildSQL(Argument::type(SelectQuery::class))
->willReturn('SELECT * FROM eventstore WHERE (aggregate = :aggregate) AND (aggregate_id = :id) AND (playhead > :playhead) AND (archived = :archived) ORDER BY id ASC');

$abstractPlatform->createSelectSQLBuilder()
->willReturn($selectSqlBuilder->reveal());
$abstractPlatform->getDateTimeTzFormatString()->willReturn('Y-m-d H:i:s');
$abstractPlatform->createSelectSQLBuilder()->shouldBeCalledOnce()->willReturn($selectSqlBuilder->reveal());
$abstractPlatform->getDateTimeTzFormatString()->shouldBeCalledOnce()->willReturn('Y-m-d H:i:s');
$abstractPlatform->convertFromBoolean('0')->shouldBeCalledTimes(2)->willReturn(false);

$connection->getDatabasePlatform()->willReturn($abstractPlatform->reveal());

Expand Down

0 comments on commit 7e76aef

Please sign in to comment.