2019-11-25 11:54:25 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Exception;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
|
2022-09-23 11:05:17 -05:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
2019-11-25 11:54:25 -06:00
|
|
|
|
|
|
|
class ShortUrlNotFoundExceptionTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideMessages
|
|
|
|
*/
|
|
|
|
public function properlyCreatesExceptionFromNotFoundShortCode(
|
|
|
|
string $expectedMessage,
|
|
|
|
string $shortCode,
|
2021-05-23 05:31:10 -05:00
|
|
|
?string $domain,
|
2019-11-25 11:54:25 -06:00
|
|
|
): void {
|
2019-12-01 03:14:29 -06:00
|
|
|
$expectedAdditional = ['shortCode' => $shortCode];
|
|
|
|
if ($domain !== null) {
|
|
|
|
$expectedAdditional['domain'] = $domain;
|
|
|
|
}
|
|
|
|
|
2022-04-23 07:00:47 -05:00
|
|
|
$e = ShortUrlNotFoundException::fromNotFound(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain));
|
2019-12-01 03:14:29 -06:00
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals($expectedMessage, $e->getMessage());
|
|
|
|
self::assertEquals($expectedMessage, $e->getDetail());
|
|
|
|
self::assertEquals('Short URL not found', $e->getTitle());
|
2022-08-13 10:15:04 -05:00
|
|
|
self::assertEquals('https://shlink.io/api/error/short-url-not-found', $e->getType());
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(404, $e->getStatus());
|
|
|
|
self::assertEquals($expectedAdditional, $e->getAdditionalData());
|
2019-11-25 11:54:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideMessages(): iterable
|
|
|
|
{
|
|
|
|
yield 'without domain' => [
|
|
|
|
'No URL found with short code "abc123"',
|
|
|
|
'abc123',
|
|
|
|
null,
|
|
|
|
];
|
|
|
|
yield 'with domain' => [
|
|
|
|
'No URL found with short code "bar" for domain "foo"',
|
|
|
|
'bar',
|
|
|
|
'foo',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|