diff --git a/module/Core/src/EventDispatcher/Event/ShortUrlCreated.php b/module/Core/src/EventDispatcher/Event/ShortUrlCreated.php index 4055935f..0d929ec7 100644 --- a/module/Core/src/EventDispatcher/Event/ShortUrlCreated.php +++ b/module/Core/src/EventDispatcher/Event/ShortUrlCreated.php @@ -15,9 +15,7 @@ final readonly class ShortUrlCreated implements JsonSerializable, JsonUnserializ public function jsonSerialize(): array { - return [ - 'shortUrlId' => $this->shortUrlId, - ]; + return ['shortUrlId' => $this->shortUrlId]; } public static function fromPayload(array $payload): self diff --git a/module/Core/test/EventDispatcher/Event/ShortUrlCreatedTest.php b/module/Core/test/EventDispatcher/Event/ShortUrlCreatedTest.php new file mode 100644 index 00000000..4b59f2e4 --- /dev/null +++ b/module/Core/test/EventDispatcher/Event/ShortUrlCreatedTest.php @@ -0,0 +1,29 @@ + $shortUrlId], new ShortUrlCreated($shortUrlId)->jsonSerialize()); + } + + #[Test] + #[TestWith([['shortUrlId' => '123'], '123'])] + #[TestWith([[], ''])] + public function creationFromPayload(array $payload, string $expectedShortUrlId): void + { + $event = ShortUrlCreated::fromPayload($payload); + self::assertEquals($expectedShortUrlId, $event->shortUrlId); + } +} diff --git a/module/Core/test/EventDispatcher/Event/UrlVisitedTest.php b/module/Core/test/EventDispatcher/Event/UrlVisitedTest.php new file mode 100644 index 00000000..ebcfa265 --- /dev/null +++ b/module/Core/test/EventDispatcher/Event/UrlVisitedTest.php @@ -0,0 +1,35 @@ + $visitId, 'originalIpAddress' => null], + new UrlVisited($visitId)->jsonSerialize(), + ); + } + + #[Test] + #[TestWith([['visitId' => '123', 'originalIpAddress' => '1.2.3.4'], '123', '1.2.3.4'])] + #[TestWith([['visitId' => '123'], '123', null])] + #[TestWith([['originalIpAddress' => '1.2.3.4'], '', '1.2.3.4'])] + #[TestWith([[], '', null])] + public function creationFromPayload(array $payload, string $expectedVisitId, string|null $expectedIpAddress): void + { + $event = UrlVisited::fromPayload($payload); + self::assertEquals($expectedVisitId, $event->visitId); + self::assertEquals($expectedIpAddress, $event->originalIpAddress); + } +}