Completed
Push — master ( 67e465...aa77c9 )
by Alejandro
13s queued 10s
created

InvalidShortCodeExceptionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

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