2021-01-04 13:15:42 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Exception;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Exception\DomainNotFoundException;
|
|
|
|
|
|
|
|
use function sprintf;
|
|
|
|
|
|
|
|
class DomainNotFoundExceptionTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @test */
|
2021-07-29 11:23:41 -05:00
|
|
|
public function properlyCreatesExceptionFromId(): void
|
2021-01-04 13:15:42 -06: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 10:15:04 -05:00
|
|
|
self::assertEquals('https://shlink.io/api/error/domain-not-found', $e->getType());
|
2021-01-04 13:15:42 -06:00
|
|
|
self::assertEquals(['id' => $id], $e->getAdditionalData());
|
|
|
|
self::assertEquals(404, $e->getStatus());
|
|
|
|
}
|
2021-07-29 11:23:41 -05:00
|
|
|
|
|
|
|
/** @test */
|
|
|
|
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 10:15:04 -05:00
|
|
|
self::assertEquals('https://shlink.io/api/error/domain-not-found', $e->getType());
|
2021-07-29 11:23:41 -05:00
|
|
|
self::assertEquals(['authority' => $authority], $e->getAdditionalData());
|
|
|
|
self::assertEquals(404, $e->getStatus());
|
|
|
|
}
|
2021-01-04 13:15:42 -06:00
|
|
|
}
|