mirror of
https://github.com/shlinkio/shlink.git
synced 2025-12-10 09:33:48 -06:00
Add tests for events
This commit is contained in:
parent
7812a85b39
commit
9432a5ba78
@ -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
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\EventDispatcher\Event;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\TestWith;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlCreated;
|
||||
|
||||
class ShortUrlCreatedTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function jsonSerialization(): void
|
||||
{
|
||||
$shortUrlId = 'abc123';
|
||||
self::assertEquals(['shortUrlId' => $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);
|
||||
}
|
||||
}
|
||||
35
module/Core/test/EventDispatcher/Event/UrlVisitedTest.php
Normal file
35
module/Core/test/EventDispatcher/Event/UrlVisitedTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\EventDispatcher\Event;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\TestWith;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\UrlVisited;
|
||||
|
||||
class UrlVisitedTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function jsonSerialization(): void
|
||||
{
|
||||
$visitId = 'abc123';
|
||||
self::assertEquals(
|
||||
['visitId' => $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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user