shlink/module/Core/test/Exception/DeleteShortUrlExceptionTest.php

61 lines
1.7 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\TestCase;
2019-02-17 13:28:34 -06:00
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
use function Functional\map;
use function range;
2019-02-17 13:28:34 -06:00
use function sprintf;
class DeleteShortUrlExceptionTest extends TestCase
{
2019-02-17 13:28:34 -06:00
use StringUtilsTrait;
/**
* @test
2019-02-17 13:28:34 -06:00
* @dataProvider provideThresholds
*/
public function fromVisitsThresholdGeneratesMessageProperly(
int $threshold,
string $shortCode,
string $expectedMessage
2019-02-17 13:28:34 -06:00
): void {
$e = DeleteShortUrlException::fromVisitsThreshold($threshold, $shortCode);
2019-02-17 13:28:34 -06:00
$this->assertEquals($threshold, $e->getVisitsThreshold());
$this->assertEquals($expectedMessage, $e->getMessage());
2018-11-17 12:23:25 -06:00
$this->assertEquals(0, $e->getCode());
2019-02-17 13:28:34 -06:00
$this->assertNull($e->getPrevious());
}
/**
* @test
* @dataProvider provideThresholds
*/
2019-02-17 13:28:34 -06:00
public function visitsThresholdIsProperlyReturned(int $threshold): void
{
$e = new DeleteShortUrlException($threshold);
2019-02-17 13:28:34 -06:00
$this->assertEquals($threshold, $e->getVisitsThreshold());
2019-02-17 13:28:34 -06:00
$this->assertEquals('', $e->getMessage());
$this->assertEquals(0, $e->getCode());
$this->assertNull($e->getPrevious());
}
public function provideThresholds(): array
{
return map(range(5, 50, 5), function (int $number) {
2019-02-17 13:28:34 -06:00
$shortCode = $this->generateRandomString(6);
return [$number, $shortCode, sprintf(
'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
$shortCode,
$number
)];
});
}
}