Passed
Pull Request — master (#588)
by Alejandro
03:34
created

ShortUrlNotFoundExceptionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

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
10
class ShortUrlNotFoundExceptionTest extends TestCase
11
{
12
    /**
13
     * @test
14
     * @dataProvider provideMessages
15
     */
16
    public function properlyCreatesExceptionFromNotFoundShortCode(
17
        string $expectedMessage,
18
        string $shortCode,
19
        ?string $domain
20
    ): void {
21
        $expectedAdditional = ['shortCode' => $shortCode];
22
        if ($domain !== null) {
23
            $expectedAdditional['domain'] = $domain;
24
        }
25
26
        $e = ShortUrlNotFoundException::fromNotFoundShortCode($shortCode, $domain);
27
28
        $this->assertEquals($expectedMessage, $e->getMessage());
29
        $this->assertEquals($expectedMessage, $e->getDetail());
30
        $this->assertEquals('Short URL not found', $e->getTitle());
31
        $this->assertEquals('INVALID_SHORTCODE', $e->getType());
32
        $this->assertEquals(404, $e->getStatus());
33
        $this->assertEquals($expectedAdditional, $e->getAdditionalData());
34
    }
35
36
    public function provideMessages(): iterable
37
    {
38
        yield 'without domain' => [
39
            'No URL found with short code "abc123"',
40
            'abc123',
41
            null,
42
        ];
43
        yield 'with domain' => [
44
            'No URL found with short code "bar" for domain "foo"',
45
            'bar',
46
            'foo',
47
        ];
48
    }
49
}
50