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

51 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2019-10-05 10:26:10 -05:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
use function Functional\map;
use function range;
use function Shlinkio\Shlink\Core\generateRandomShortCode;
2019-02-17 13:28:34 -06:00
use function sprintf;
class DeleteShortUrlExceptionTest extends TestCase
{
/**
* @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());
$this->assertEquals($expectedMessage, $e->getDetail());
$this->assertEquals([
'shortCode' => $shortCode,
'threshold' => $threshold,
], $e->getAdditionalData());
$this->assertEquals('Cannot delete short URL', $e->getTitle());
$this->assertEquals('INVALID_SHORTCODE_DELETION', $e->getType());
$this->assertEquals(422, $e->getStatus());
}
public function provideThresholds(): array
{
return map(range(5, 50, 5), function (int $number) {
return [$number, $shortCode = generateRandomShortCode(6), sprintf(
2019-02-17 13:28:34 -06:00
'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
$shortCode,
2020-01-01 13:48:31 -06:00
$number,
2019-02-17 13:28:34 -06:00
)];
});
}
}