Improved domain exception tests to cover more possible mutants

This commit is contained in:
Alejandro Celaya
2019-12-01 10:14:29 +01:00
parent 8cc4d3e6d5
commit 1bf56b658b
9 changed files with 115 additions and 5 deletions

View File

@@ -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

View File

@@ -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());
}

View File

@@ -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

View File

@@ -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

View 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());
}
}