Reduced amount of dead lines in tests

This commit is contained in:
Alejandro Celaya
2019-02-17 20:28:34 +01:00
parent 1bcd03b150
commit 687a1cc9c7
100 changed files with 481 additions and 938 deletions

View File

@@ -4,61 +4,56 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
use function Functional\map;
use function range;
use function sprintf;
class DeleteShortUrlExceptionTest extends TestCase
{
use StringUtilsTrait;
/**
* @test
* @dataProvider provideMessages
* @dataProvider provideThresholds
*/
public function fromVisitsThresholdGeneratesMessageProperly(
int $threshold,
string $shortCode,
string $expectedMessage
) {
): void {
$e = DeleteShortUrlException::fromVisitsThreshold($threshold, $shortCode);
$this->assertEquals($threshold, $e->getVisitsThreshold());
$this->assertEquals($expectedMessage, $e->getMessage());
$this->assertEquals(0, $e->getCode());
}
public function provideMessages(): array
{
return [
[
50,
'abc123',
'Impossible to delete short URL with short code "abc123" since it has more than "50" visits.',
],
[
33,
'def456',
'Impossible to delete short URL with short code "def456" since it has more than "33" visits.',
],
[
5713,
'foobar',
'Impossible to delete short URL with short code "foobar" since it has more than "5713" visits.',
],
];
$this->assertNull($e->getPrevious());
}
/**
* @test
* @dataProvider provideThresholds
*/
public function visitsThresholdIsProperlyReturned(int $threshold)
public function visitsThresholdIsProperlyReturned(int $threshold): void
{
$e = new DeleteShortUrlException($threshold);
$this->assertEquals($threshold, $e->getVisitsThreshold());
$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) {
return [$number];
$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
)];
});
}
}

View File

@@ -14,7 +14,7 @@ class InvalidShortCodeExceptionTest extends TestCase
* @test
* @dataProvider providePrevious
*/
public function properlyCreatesExceptionFromCharset(?Throwable $prev)
public function properlyCreatesExceptionFromCharset(?Throwable $prev): void
{
$e = InvalidShortCodeException::fromCharset('abc123', 'def456', $prev);
@@ -23,18 +23,14 @@ class InvalidShortCodeExceptionTest extends TestCase
$this->assertEquals($prev, $e->getPrevious());
}
public function providePrevious(): array
public function providePrevious(): iterable
{
return [
[null],
[new Exception('Previos error', 10)],
];
yield 'null previous' => [null];
yield 'instance previous' => [new Exception('Previous error', 10)];
}
/**
* @test
*/
public function properlyCreatesExceptionFromNotFoundShortCode()
/** @test */
public function properlyCreatesExceptionFromNotFoundShortCode(): void
{
$e = InvalidShortCodeException::fromNotFoundShortCode('abc123');

View File

@@ -14,7 +14,7 @@ class InvalidUrlExceptionTest extends TestCase
* @test
* @dataProvider providePrevious
*/
public function properlyCreatesExceptionFromUrl(?Throwable $prev)
public function properlyCreatesExceptionFromUrl(?Throwable $prev): void
{
$e = InvalidUrlException::fromUrl('http://the_url.com', $prev);
@@ -23,11 +23,9 @@ class InvalidUrlExceptionTest extends TestCase
$this->assertEquals($prev, $e->getPrevious());
}
public function providePrevious(): array
public function providePrevious(): iterable
{
return [
[null],
[new Exception('Previos error', 10)],
];
yield 'null previous' => [null];
yield 'instance previous' => [new Exception('Previous error', 10)];
}
}