mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-27 01:11:39 -06:00
Improved domain exception tests to cover more possible mutants
This commit is contained in:
parent
8cc4d3e6d5
commit
1bf56b658b
@ -27,6 +27,14 @@ class DeleteShortUrlExceptionTest extends TestCase
|
||||
|
||||
$this->assertEquals($threshold, $e->getVisitsThreshold());
|
||||
$this->assertEquals($expectedMessage, $e->getMessage());
|
||||
$this->assertEquals($expectedMessage, $e->getDetail());
|
||||
$this->assertEquals([
|
||||
'shortCode' => $shortCode,
|
||||
'threshold' => $threshold,
|
||||
], $e->getAdditionalData());
|
||||
$this->assertEquals('Cannot delete short URL', $e->getTitle());
|
||||
$this->assertEquals('INVALID_SHORTCODE_DELETION', $e->getType());
|
||||
$this->assertEquals(422, $e->getStatus());
|
||||
}
|
||||
|
||||
public function provideThresholds(): array
|
||||
|
@ -10,6 +10,8 @@ use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
|
||||
use Throwable;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class InvalidUrlExceptionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
@ -18,10 +20,17 @@ class InvalidUrlExceptionTest extends TestCase
|
||||
*/
|
||||
public function properlyCreatesExceptionFromUrl(?Throwable $prev): void
|
||||
{
|
||||
$e = InvalidUrlException::fromUrl('http://the_url.com', $prev);
|
||||
$url = 'http://the_url.com';
|
||||
$expectedMessage = sprintf('Provided URL %s is invalid. Try with a different one.', $url);
|
||||
$e = InvalidUrlException::fromUrl($url, $prev);
|
||||
|
||||
$this->assertEquals('Provided URL http://the_url.com is invalid. Try with a different one.', $e->getMessage());
|
||||
$this->assertEquals($expectedMessage, $e->getMessage());
|
||||
$this->assertEquals($expectedMessage, $e->getDetail());
|
||||
$this->assertEquals('Invalid URL', $e->getTitle());
|
||||
$this->assertEquals('INVALID_URL', $e->getType());
|
||||
$this->assertEquals(['url' => $url], $e->getAdditionalData());
|
||||
$this->assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getCode());
|
||||
$this->assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getStatus());
|
||||
$this->assertEquals($prev, $e->getPrevious());
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,19 @@ class NonUniqueSlugExceptionTest extends TestCase
|
||||
*/
|
||||
public function properlyCreatesExceptionFromSlug(string $expectedMessage, string $slug, ?string $domain): void
|
||||
{
|
||||
$expectedAdditional = ['customSlug' => $slug];
|
||||
if ($domain !== null) {
|
||||
$expectedAdditional['domain'] = $domain;
|
||||
}
|
||||
|
||||
$e = NonUniqueSlugException::fromSlug($slug, $domain);
|
||||
|
||||
$this->assertEquals($expectedMessage, $e->getMessage());
|
||||
$this->assertEquals($expectedMessage, $e->getDetail());
|
||||
$this->assertEquals('Invalid custom slug', $e->getTitle());
|
||||
$this->assertEquals('INVALID_SLUG', $e->getType());
|
||||
$this->assertEquals(400, $e->getStatus());
|
||||
$this->assertEquals($expectedAdditional, $e->getAdditionalData());
|
||||
}
|
||||
|
||||
public function provideMessages(): iterable
|
||||
|
@ -18,8 +18,19 @@ class ShortUrlNotFoundExceptionTest extends TestCase
|
||||
string $shortCode,
|
||||
?string $domain
|
||||
): void {
|
||||
$expectedAdditional = ['shortCode' => $shortCode];
|
||||
if ($domain !== null) {
|
||||
$expectedAdditional['domain'] = $domain;
|
||||
}
|
||||
|
||||
$e = ShortUrlNotFoundException::fromNotFoundShortCode($shortCode, $domain);
|
||||
|
||||
$this->assertEquals($expectedMessage, $e->getMessage());
|
||||
$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());
|
||||
}
|
||||
|
||||
public function provideMessages(): iterable
|
||||
|
28
module/Core/test/Exception/TagNotFoundExceptionTest.php
Normal file
28
module/Core/test/Exception/TagNotFoundExceptionTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Exception;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class TagNotFoundExceptionTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function properlyCreatesExceptionFromNotFoundTag(): void
|
||||
{
|
||||
$tag = 'foo';
|
||||
$expectedMessage = sprintf('Tag with name "%s" could not be found', $tag);
|
||||
$e = TagNotFoundException::fromTag($tag);
|
||||
|
||||
$this->assertEquals($expectedMessage, $e->getMessage());
|
||||
$this->assertEquals($expectedMessage, $e->getDetail());
|
||||
$this->assertEquals('Tag not found', $e->getTitle());
|
||||
$this->assertEquals('TAG_NOT_FOUND', $e->getType());
|
||||
$this->assertEquals(['tag' => $tag], $e->getAdditionalData());
|
||||
$this->assertEquals(404, $e->getStatus());
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ class MissingAuthenticationException extends RuntimeException implements Problem
|
||||
public static function fromExpectedTypes(array $expectedTypes): self
|
||||
{
|
||||
$e = new self(sprintf(
|
||||
'Expected one of the following authentication headers, but none were provided, ["%s"]',
|
||||
'Expected one of the following authentication headers, ["%s"], but none were provided',
|
||||
implode('", "', $expectedTypes)
|
||||
));
|
||||
|
||||
|
@ -17,7 +17,7 @@ class AuthenticationTest extends ApiTestCase
|
||||
public function authorizationErrorIsReturnedIfNoApiKeyIsSent(): void
|
||||
{
|
||||
$expectedDetail = sprintf(
|
||||
'Expected one of the following authentication headers, but none were provided, ["%s"]',
|
||||
'Expected one of the following authentication headers, ["%s"], but none were provided',
|
||||
implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS)
|
||||
);
|
||||
|
||||
|
@ -37,7 +37,7 @@ class RequestToAuthPluginTest extends TestCase
|
||||
|
||||
$this->expectException(MissingAuthenticationException::class);
|
||||
$this->expectExceptionMessage(sprintf(
|
||||
'Expected one of the following authentication headers, but none were provided, ["%s"]',
|
||||
'Expected one of the following authentication headers, ["%s"], but none were provided',
|
||||
implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS)
|
||||
));
|
||||
|
||||
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Exception;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Rest\Exception\MissingAuthenticationException;
|
||||
|
||||
use function implode;
|
||||
use function sprintf;
|
||||
|
||||
class MissingAuthenticationExceptionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideExpectedTypes
|
||||
*/
|
||||
public function exceptionIsProperlyCreatedFromExpectedTypes(array $expectedTypes): void
|
||||
{
|
||||
$expectedMessage = sprintf(
|
||||
'Expected one of the following authentication headers, ["%s"], but none were provided',
|
||||
implode('", "', $expectedTypes)
|
||||
);
|
||||
|
||||
$e = MissingAuthenticationException::fromExpectedTypes($expectedTypes);
|
||||
|
||||
$this->assertEquals($expectedMessage, $e->getMessage());
|
||||
$this->assertEquals($expectedMessage, $e->getDetail());
|
||||
$this->assertEquals('Invalid authorization', $e->getTitle());
|
||||
$this->assertEquals('INVALID_AUTHORIZATION', $e->getType());
|
||||
$this->assertEquals(401, $e->getStatus());
|
||||
$this->assertEquals(['expectedTypes' => $expectedTypes], $e->getAdditionalData());
|
||||
}
|
||||
|
||||
public function provideExpectedTypes(): iterable
|
||||
{
|
||||
yield [['foo', 'bar']];
|
||||
yield [['something']];
|
||||
yield [[]];
|
||||
yield [['foo', 'bar', 'baz']];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user