shlink/module/Core/test/Exception/NonUniqueSlugExceptionTest.php

46 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2019-10-05 10:26:10 -05:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
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
{
$expectedAdditional = ['customSlug' => $slug];
if ($domain !== null) {
$expectedAdditional['domain'] = $domain;
}
$e = NonUniqueSlugException::fromSlug($slug, $domain);
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());
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());
}
2023-02-09 02:32:38 -06:00
public static function provideMessages(): iterable
{
yield 'without domain' => [
'Provided slug "foo" is already in use.',
'foo',
null,
];
yield 'with domain' => [
'Provided slug "baz" is already in use for domain "bar".',
'baz',
'bar',
];
}
}