2019-10-01 14:42:35 -05:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2019-10-01 14:42:35 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Exception;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
|
|
|
|
|
|
|
|
class NonUniqueSlugExceptionTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideMessages
|
|
|
|
*/
|
|
|
|
public function properlyCreatesExceptionFromSlug(string $expectedMessage, string $slug, ?string $domain): void
|
|
|
|
{
|
2019-12-01 03:14:29 -06:00
|
|
|
$expectedAdditional = ['customSlug' => $slug];
|
|
|
|
if ($domain !== null) {
|
|
|
|
$expectedAdditional['domain'] = $domain;
|
|
|
|
}
|
|
|
|
|
2019-10-01 14:42:35 -05:00
|
|
|
$e = NonUniqueSlugException::fromSlug($slug, $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('Invalid custom slug', $e->getTitle());
|
2022-08-13 10:15:04 -05:00
|
|
|
self::assertEquals('https://shlink.io/api/error/non-unique-slug', $e->getType());
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(400, $e->getStatus());
|
|
|
|
self::assertEquals($expectedAdditional, $e->getAdditionalData());
|
2019-10-01 14:42:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideMessages(): iterable
|
|
|
|
{
|
|
|
|
yield 'without domain' => [
|
2019-11-24 16:32:37 -06:00
|
|
|
'Provided slug "foo" is already in use.',
|
2019-10-01 14:42:35 -05:00
|
|
|
'foo',
|
|
|
|
null,
|
|
|
|
];
|
|
|
|
yield 'with domain' => [
|
2019-11-24 16:32:37 -06:00
|
|
|
'Provided slug "baz" is already in use for domain "bar".',
|
2019-10-01 14:42:35 -05:00
|
|
|
'baz',
|
|
|
|
'bar',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|