Completed
Push — master ( 5c5dde...08bd4f )
by Alejandro
17s queued 10s
created

DeleteShortUrlExceptionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromVisitsThresholdGeneratesMessageProperly() 0 11 1
A provideThresholds() 0 8 1
A visitsThresholdIsProperlyReturned() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Core\Exception;
5
6
use PHPUnit\Framework\TestCase;
7
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
8
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
9
use function Functional\map;
10
use function range;
11
use function sprintf;
12
13
class DeleteShortUrlExceptionTest extends TestCase
14
{
15
    use StringUtilsTrait;
16
17
    /**
18
     * @test
19
     * @dataProvider provideThresholds
20
     */
21
    public function fromVisitsThresholdGeneratesMessageProperly(
22
        int $threshold,
23
        string $shortCode,
24
        string $expectedMessage
25
    ): void {
26
        $e = DeleteShortUrlException::fromVisitsThreshold($threshold, $shortCode);
27
28
        $this->assertEquals($threshold, $e->getVisitsThreshold());
29
        $this->assertEquals($expectedMessage, $e->getMessage());
30
        $this->assertEquals(0, $e->getCode());
31
        $this->assertNull($e->getPrevious());
32
    }
33
34
    /**
35
     * @test
36
     * @dataProvider provideThresholds
37
     */
38
    public function visitsThresholdIsProperlyReturned(int $threshold): void
39
    {
40
        $e = new DeleteShortUrlException($threshold);
41
42
        $this->assertEquals($threshold, $e->getVisitsThreshold());
43
        $this->assertEquals('', $e->getMessage());
44
        $this->assertEquals(0, $e->getCode());
45
        $this->assertNull($e->getPrevious());
46
    }
47
48
    public function provideThresholds(): array
49
    {
50
        return map(range(5, 50, 5), function (int $number) {
51
            $shortCode = $this->generateRandomString(6);
52
            return [$number, $shortCode, sprintf(
53
                'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
54
                $shortCode,
55
                $number
56
            )];
57
        });
58
    }
59
}
60