Completed
Push — master ( 038254...115ca0 )
by Alejandro
06:27
created

InvalidShortCodeExceptionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A properlyCreatesExceptionFromCharset() 0 7 2
A properlyCreatesExceptionFromNotFoundShortCode() 0 5 1
A providePrevious() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Core\Exception;
6
7
use Exception;
8
use PHPUnit\Framework\TestCase;
9
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
10
use Throwable;
11
12
class InvalidShortCodeExceptionTest extends TestCase
13
{
14
    /**
15
     * @test
16
     * @dataProvider providePrevious
17
     */
18
    public function properlyCreatesExceptionFromCharset(?Throwable $prev): void
19
    {
20
        $e = InvalidShortCodeException::fromCharset('abc123', 'def456', $prev);
21
22
        $this->assertEquals('Provided short code "abc123" does not match the char set "def456"', $e->getMessage());
23
        $this->assertEquals($prev !== null ? $prev->getCode() : -1, $e->getCode());
24
        $this->assertEquals($prev, $e->getPrevious());
25
    }
26
27
    public function providePrevious(): iterable
28
    {
29
        yield 'null previous' => [null];
30
        yield 'instance previous' => [new Exception('Previous error', 10)];
31
    }
32
33
    /** @test */
34
    public function properlyCreatesExceptionFromNotFoundShortCode(): void
35
    {
36
        $e = InvalidShortCodeException::fromNotFoundShortCode('abc123');
37
38
        $this->assertEquals('Provided short code "abc123" does not belong to a short URL', $e->getMessage());
39
    }
40
}
41