Migrate from PHPUnit annotations to native attributes

This commit is contained in:
Alejandro Celaya
2023-02-09 20:42:18 +01:00
parent 650a286982
commit 04bbd471ff
188 changed files with 776 additions and 1082 deletions

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
@@ -15,10 +17,7 @@ use function sprintf;
class DeleteShortUrlExceptionTest extends TestCase
{
/**
* @test
* @dataProvider provideThresholds
*/
#[Test, DataProvider('provideThresholds')]
public function fromVisitsThresholdGeneratesMessageProperly(
int $threshold,
string $shortCode,
@@ -52,7 +51,7 @@ class DeleteShortUrlExceptionTest extends TestCase
});
}
/** @test */
#[Test]
public function domainIsPartOfAdditionalWhenProvidedInIdentifier(): void
{
$e = DeleteShortUrlException::fromVisitsThreshold(

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\DomainNotFoundException;
@@ -11,7 +12,7 @@ use function sprintf;
class DomainNotFoundExceptionTest extends TestCase
{
/** @test */
#[Test]
public function properlyCreatesExceptionFromId(): void
{
$id = '123';
@@ -26,7 +27,7 @@ class DomainNotFoundExceptionTest extends TestCase
self::assertEquals(404, $e->getStatus());
}
/** @test */
#[Test]
public function properlyCreatesExceptionFromAuthority(): void
{
$authority = 'example.com';

View File

@@ -4,15 +4,14 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\ForbiddenTagOperationException;
class ForbiddenTagOperationExceptionTest extends TestCase
{
/**
* @test
* @dataProvider provideExceptions
*/
#[Test, DataProvider('provideExceptions')]
public function createsExpectedExceptionForDeletion(
ForbiddenTagOperationException $e,
string $expectedMessage,

View File

@@ -6,6 +6,8 @@ namespace ShlinkioTest\Shlink\Core\Exception;
use Exception;
use Fig\Http\Message\StatusCodeInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
use Throwable;
@@ -14,10 +16,7 @@ use function sprintf;
class InvalidUrlExceptionTest extends TestCase
{
/**
* @test
* @dataProvider providePrevious
*/
#[Test, DataProvider('providePrevious')]
public function properlyCreatesExceptionFromUrl(?Throwable $prev): void
{
$url = 'http://the_url.com';

View File

@@ -6,6 +6,8 @@ namespace ShlinkioTest\Shlink\Core\Exception;
use Exception;
use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException;
use Shlinkio\Shlink\Core\Exception\RuntimeException;
@@ -14,7 +16,7 @@ use Throwable;
class IpCannotBeLocatedExceptionTest extends TestCase
{
/** @test */
#[Test]
public function forEmptyAddressInitializesException(): void
{
$e = IpCannotBeLocatedException::forEmptyAddress();
@@ -26,7 +28,7 @@ class IpCannotBeLocatedExceptionTest extends TestCase
self::assertEquals(UnlocatableIpType::EMPTY_ADDRESS, $e->type);
}
/** @test */
#[Test]
public function forLocalhostInitializesException(): void
{
$e = IpCannotBeLocatedException::forLocalhost();
@@ -38,10 +40,7 @@ class IpCannotBeLocatedExceptionTest extends TestCase
self::assertEquals(UnlocatableIpType::LOCALHOST, $e->type);
}
/**
* @test
* @dataProvider provideErrors
*/
#[Test, DataProvider('provideErrors')]
public function forErrorInitializesException(Throwable $prev): void
{
$e = IpCannotBeLocatedException::forError($prev);

View File

@@ -6,12 +6,13 @@ namespace ShlinkioTest\Shlink\Core\Exception;
use Fig\Http\Message\StatusCodeInterface;
use JsonException;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\MalformedBodyException;
class MalformedBodyExceptionTest extends TestCase
{
/** @test */
#[Test]
public function createsExpectedException(): void
{
$prev = new JsonException();

View File

@@ -4,15 +4,14 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
class NonUniqueSlugExceptionTest extends TestCase
{
/**
* @test
* @dataProvider provideMessages
*/
#[Test, DataProvider('provideMessages')]
public function properlyCreatesExceptionFromSlug(string $expectedMessage, string $slug, ?string $domain): void
{
$expectedAdditional = ['customSlug' => $slug];

View File

@@ -4,16 +4,15 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
class ShortUrlNotFoundExceptionTest extends TestCase
{
/**
* @test
* @dataProvider provideMessages
*/
#[Test, DataProvider('provideMessages')]
public function properlyCreatesExceptionFromNotFoundShortCode(
string $expectedMessage,
string $shortCode,

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\TagConflictException;
use Shlinkio\Shlink\Core\Tag\Model\TagRenaming;
@@ -12,7 +13,7 @@ use function sprintf;
class TagConflictExceptionTest extends TestCase
{
/** @test */
#[Test]
public function properlyCreatesExceptionForExistingTag(): void
{
$oldName = 'foo';

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
@@ -11,7 +12,7 @@ use function sprintf;
class TagNotFoundExceptionTest extends TestCase
{
/** @test */
#[Test]
public function properlyCreatesExceptionFromNotFoundTag(): void
{
$tag = 'foo';

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Core\Exception;
use Fig\Http\Message\StatusCodeInterface;
use Laminas\InputFilter\InputFilterInterface;
use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Shlinkio\Shlink\Core\Exception\ValidationException;
@@ -17,10 +19,7 @@ use function print_r;
class ValidationExceptionTest extends TestCase
{
/**
* @test
* @dataProvider provideExceptions
*/
#[Test, DataProvider('provideExceptions')]
public function createsExceptionFromInputFilter(?Throwable $prev): void
{
$invalidData = [