Skip to content
This repository was archived by the owner on Sep 6, 2025. It is now read-only.

Commit d2705d9

Browse files
Enforce that a DomainMessage::getId is a string
1 parent 1c32582 commit d2705d9

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/Domain/DomainMessage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ final class DomainMessage
2828
private $version;
2929

3030
/**
31-
* @param string $id
31+
* @param AggregateIdInterface|string $id
3232
* @param $version
3333
* @param mixed $payload
3434
* @param \DateTimeImmutable $recordedOn
3535
*/
3636
public function __construct($id, $version, $payload, \DateTimeImmutable $recordedOn)
3737
{
38-
$this->id = $id;
38+
$this->id = (string) $id;
3939
$this->payload = $payload;
4040
$this->recordedOn = $recordedOn->setTimezone(new \DateTimeZone('UTC'));
4141
$this->version = $version;
@@ -58,15 +58,15 @@ public function getPayload()
5858
}
5959

6060
/**
61-
* {@inheritDoc}
61+
* @inheritDoc
6262
*/
6363
public function getRecordedOn()
6464
{
6565
return $this->recordedOn;
6666
}
6767

6868
/**
69-
* {@inheritDoc}
69+
* @inheritDoc
7070
*/
7171
public function getType()
7272
{

src/EventStore/Adapter/RedisAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function countEventsFor(StreamName $streamName, AggregateIdInterface $agg
5959
return count($this->redis->lrange($this->getNamespaceKey($streamName, $aggregateId), 0, -1));
6060
}
6161

62-
private function getNamespaceKey(StreamName $streamName, AggregateIdInterface $aggregateId)
62+
private function getNamespaceKey(StreamName $streamName, $aggregateId)
6363
{
64-
return "events:{$streamName}:{$aggregateId}";
64+
return sprintf('events:%s:%s', $streamName, $aggregateId);
6565
}
6666
}

tests/Domain/DomainMessageTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public function itShouldCreateAUuidFromConstructor(
2424
\DateTimeImmutable $date
2525
) {
2626
$message = new DomainMessage($aggregateId, $version, $payload, $date);
27+
2728
$this->assertInstanceOf(DomainMessage::class, $message);
28-
$this->assertSame($aggregateId, $message->getId());
29+
$this->assertSame((string) $aggregateId, $message->getId());
2930
$this->assertSame($version, $message->getVersion());
3031
$this->assertSame($payload, $message->getPayload());
3132
$this->assertEquals($date, $message->getRecordedOn());
@@ -47,6 +48,7 @@ public function itShouldCreateAUuidFromNamedConstructor(
4748
\DateTimeImmutable $date
4849
) {
4950
$message = DomainMessage::recordNow($aggregateId, $version, $payload);
51+
5052
$this->assertInstanceOf(DomainMessage::class, $message);
5153

5254
$this->assertNotEmpty((int)$message->getRecordedOn()->format('u'), 'Expected microseconds to be set');

tests/EventStore/EventStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace HelloFresh\Tests\Engine\EventStore;
44

55
use HelloFresh\Engine\Domain\AggregateId;
6+
use HelloFresh\Engine\Domain\AggregateIdInterface;
67
use HelloFresh\Engine\Domain\DomainMessage;
78
use HelloFresh\Engine\Domain\EventStream;
89
use HelloFresh\Engine\Domain\StreamName;
@@ -79,7 +80,7 @@ public function idDataProvider()
7980
{
8081
return [
8182
'Simple String' => [
82-
'Yolntbyaac', //You only live nine times because you are a cat
83+
'Yolntbyaac', // You only live nine times because you are a cat
8384
],
8485
'Identitiy' => [
8586
AggregateId::generate(),

0 commit comments

Comments
 (0)