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;
|
|
|
|
|
|
|
|
class ShortUrlNotFoundExceptionTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideMessages
|
|
|
|
*/
|
|
|
|
public function properlyCreatesExceptionFromNotFoundShortCode(
|
|
|
|
string $expectedMessage,
|
|
|
|
string $shortCode,
|
|
|
|
?string $domain
|
|
|
|
): void {
|
2019-12-01 03:14:29 -06:00
|
|
|
$expectedAdditional = ['shortCode' => $shortCode];
|
|
|
|
if ($domain !== null) {
|
|
|
|
$expectedAdditional['domain'] = $domain;
|
|
|
|
}
|
|
|
|
|
2019-11-25 11:54:25 -06:00
|
|
|
$e = ShortUrlNotFoundException::fromNotFoundShortCode($shortCode, $domain);
|
2019-12-01 03:14:29 -06:00
|
|
|
|
2019-11-25 11:54:25 -06:00
|
|
|
$this->assertEquals($expectedMessage, $e->getMessage());
|
2019-12-01 03:14:29 -06:00
|
|
|
$this->assertEquals($expectedMessage, $e->getDetail());
|
|
|
|
$this->assertEquals('Short URL not found', $e->getTitle());
|
|
|
|
$this->assertEquals('INVALID_SHORTCODE', $e->getType());
|
|
|
|
$this->assertEquals(404, $e->getStatus());
|
|
|
|
$this->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',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|