2021-01-04 22:15:42 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Exception;
|
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2021-01-04 22:15:42 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Exception\DomainNotFoundException;
|
|
|
|
|
|
|
|
use function sprintf;
|
|
|
|
|
|
|
|
class DomainNotFoundExceptionTest extends TestCase
|
|
|
|
{
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test]
|
2021-07-29 19:23:41 +03:00
|
|
|
public function properlyCreatesExceptionFromId(): void
|
2021-01-04 22:15:42 +03:00
|
|
|
{
|
|
|
|
$id = '123';
|
|
|
|
$expectedMessage = sprintf('Domain with id "%s" could not be found', $id);
|
|
|
|
$e = DomainNotFoundException::fromId($id);
|
|
|
|
|
|
|
|
self::assertEquals($expectedMessage, $e->getMessage());
|
|
|
|
self::assertEquals($expectedMessage, $e->getDetail());
|
|
|
|
self::assertEquals('Domain not found', $e->getTitle());
|
2022-08-13 18:15:04 +03:00
|
|
|
self::assertEquals('https://shlink.io/api/error/domain-not-found', $e->getType());
|
2021-01-04 22:15:42 +03:00
|
|
|
self::assertEquals(['id' => $id], $e->getAdditionalData());
|
|
|
|
self::assertEquals(404, $e->getStatus());
|
|
|
|
}
|
2021-07-29 19:23:41 +03:00
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test]
|
2021-07-29 19:23:41 +03:00
|
|
|
public function properlyCreatesExceptionFromAuthority(): void
|
|
|
|
{
|
|
|
|
$authority = 'example.com';
|
|
|
|
$expectedMessage = sprintf('Domain with authority "%s" could not be found', $authority);
|
|
|
|
$e = DomainNotFoundException::fromAuthority($authority);
|
|
|
|
|
|
|
|
self::assertEquals($expectedMessage, $e->getMessage());
|
|
|
|
self::assertEquals($expectedMessage, $e->getDetail());
|
|
|
|
self::assertEquals('Domain not found', $e->getTitle());
|
2022-08-13 18:15:04 +03:00
|
|
|
self::assertEquals('https://shlink.io/api/error/domain-not-found', $e->getType());
|
2021-07-29 19:23:41 +03:00
|
|
|
self::assertEquals(['authority' => $authority], $e->getAdditionalData());
|
|
|
|
self::assertEquals(404, $e->getStatus());
|
|
|
|
}
|
2021-01-04 22:15:42 +03:00
|
|
|
}
|