ShortUrlNotFoundExceptionTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 19
c 0
b 0
f 0
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provideMessages() 0 11 1
A properlyCreatesExceptionFromNotFoundShortCode() 0 18 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Core\Exception;
6
7
use PHPUnit\Framework\TestCase;
8
use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
9
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
10
11
class ShortUrlNotFoundExceptionTest extends TestCase
12
{
13
    /**
14
     * @test
15
     * @dataProvider provideMessages
16
     */
17
    public function properlyCreatesExceptionFromNotFoundShortCode(
18
        string $expectedMessage,
19
        string $shortCode,
20
        ?string $domain
21
    ): void {
22
        $expectedAdditional = ['shortCode' => $shortCode];
23
        if ($domain !== null) {
24
            $expectedAdditional['domain'] = $domain;
25
        }
26
27
        $e = ShortUrlNotFoundException::fromNotFound(new ShortUrlIdentifier($shortCode, $domain));
28
29
        self::assertEquals($expectedMessage, $e->getMessage());
30
        self::assertEquals($expectedMessage, $e->getDetail());
31
        self::assertEquals('Short URL not found', $e->getTitle());
32
        self::assertEquals('INVALID_SHORTCODE', $e->getType());
33
        self::assertEquals(404, $e->getStatus());
34
        self::assertEquals($expectedAdditional, $e->getAdditionalData());
35
    }
36
37
    public function provideMessages(): iterable
38
    {
39
        yield 'without domain' => [
40
            'No URL found with short code "abc123"',
41
            'abc123',
42
            null,
43
        ];
44
        yield 'with domain' => [
45
            'No URL found with short code "bar" for domain "foo"',
46
            'bar',
47
            'foo',
48
        ];
49
    }
50
}
51