|
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
|
|
|
|