Completed
Pull Request — master (#199)
by Alejandro
03:59
created

fromVisitsThresholdGeneratesMessageProperly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Core\Exception;
5
6
use PHPUnit\Framework\TestCase;
7
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
8
9
class DeleteShortUrlExceptionTest extends TestCase
10
{
11
    /**
12
     * @test
13
     * @dataProvider provideMessages
14
     */
15
    public function fromVisitsThresholdGeneratesMessageProperly(
16
        int $threshold,
17
        string $shortCode,
18
        string $expectedMessage
19
    ) {
20
        $e = DeleteShortUrlException::fromVisitsThreshold($threshold, $shortCode);
21
        $this->assertEquals($expectedMessage, $e->getMessage());
22
    }
23
24
    public function provideMessages(): array
25
    {
26
        return [
27
            [
28
                50,
29
                'abc123',
30
                'Impossible to delete short URL with short code "abc123" since it has more than "50" visits.',
31
            ],
32
            [
33
                33,
34
                'def456',
35
                'Impossible to delete short URL with short code "def456" since it has more than "33" visits.',
36
            ],
37
            [
38
                5713,
39
                'foobar',
40
                'Impossible to delete short URL with short code "foobar" since it has more than "5713" visits.',
41
            ],
42
        ];
43
    }
44
45
    /**
46
     * @test
47
     * @dataProvider provideThresholds
48
     */
49
    public function visitsThresholdIsProperlyReturned(int $threshold)
50
    {
51
        $e = new DeleteShortUrlException($threshold);
52
        $this->assertEquals($threshold, $e->getVisitsThreshold());
53
    }
54
55
    public function provideThresholds(): array
56
    {
57
        return \array_map(function (int $number) {
58
            return [$number];
59
        }, \range(5, 50, 5));
60
    }
61
}
62