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,13 +4,14 @@ declare(strict_types=1);
namespace ShlinkioCliTest\Shlink\CLI\Command; namespace ShlinkioCliTest\Shlink\CLI\Command;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand; use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand;
use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\CLI\Util\ExitCodes;
use Shlinkio\Shlink\TestUtils\CliTest\CliTestCase; use Shlinkio\Shlink\TestUtils\CliTest\CliTestCase;
class GenerateApiKeyTest extends CliTestCase class GenerateApiKeyTest extends CliTestCase
{ {
/** @test */ #[Test]
public function outputIsCorrect(): void public function outputIsCorrect(): void
{ {
[$output, $exitCode] = $this->exec([GenerateKeyCommand::NAME]); [$output, $exitCode] = $this->exec([GenerateKeyCommand::NAME]);

View File

@@ -5,16 +5,15 @@ declare(strict_types=1);
namespace ShlinkioCliTest\Shlink\CLI\Command; namespace ShlinkioCliTest\Shlink\CLI\Command;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand; use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand;
use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\CLI\Util\ExitCodes;
use Shlinkio\Shlink\TestUtils\CliTest\CliTestCase; use Shlinkio\Shlink\TestUtils\CliTest\CliTestCase;
class ListApiKeysTest extends CliTestCase class ListApiKeysTest extends CliTestCase
{ {
/** #[Test, DataProvider('provideFlags')]
* @test
* @dataProvider provideFlags
*/
public function generatesExpectedOutput(array $flags, string $expectedOutput): void public function generatesExpectedOutput(array $flags, string $expectedOutput): void
{ {
[$output, $exitCode] = $this->exec([ListKeysCommand::NAME, ...$flags]); [$output, $exitCode] = $this->exec([ListKeysCommand::NAME, ...$flags]);

View File

@@ -4,15 +4,14 @@ declare(strict_types=1);
namespace ShlinkioCliTest\Shlink\CLI\Command; namespace ShlinkioCliTest\Shlink\CLI\Command;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand;
use Shlinkio\Shlink\TestUtils\CliTest\CliTestCase; use Shlinkio\Shlink\TestUtils\CliTest\CliTestCase;
class ListShortUrlsTest extends CliTestCase class ListShortUrlsTest extends CliTestCase
{ {
/** #[Test, DataProvider('provideFlagsAndOutput')]
* @test
* @dataProvider provideFlagsAndOutput
*/
public function generatesExpectedOutput(array $flags, string $expectedOutput): void public function generatesExpectedOutput(array $flags, string $expectedOutput): void
{ {
[$output] = $this->exec([ListShortUrlsCommand::NAME, ...$flags], ['no']); [$output] = $this->exec([ListShortUrlsCommand::NAME, ...$flags], ['no']);

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\ApiKey; namespace ShlinkioTest\Shlink\CLI\ApiKey;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\ApiKey\RoleResolver; use Shlinkio\Shlink\CLI\ApiKey\RoleResolver;
@@ -27,10 +29,7 @@ class RoleResolverTest extends TestCase
$this->resolver = new RoleResolver($this->domainService, 'default.com'); $this->resolver = new RoleResolver($this->domainService, 'default.com');
} }
/** #[Test, DataProvider('provideRoles')]
* @test
* @dataProvider provideRoles
*/
public function properRolesAreResolvedBasedOnInput( public function properRolesAreResolvedBasedOnInput(
callable $createInput, callable $createInput,
array $expectedRoles, array $expectedRoles,
@@ -99,7 +98,7 @@ class RoleResolverTest extends TestCase
]; ];
} }
/** @test */ #[Test]
public function exceptionIsThrownWhenTryingToAddDomainOnlyLinkedToDefaultDomain(): void public function exceptionIsThrownWhenTryingToAddDomainOnlyLinkedToDefaultDomain(): void
{ {
$input = $this->createStub(InputInterface::class); $input = $this->createStub(InputInterface::class);

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Api; namespace ShlinkioTest\Shlink\CLI\Command\Api;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand; use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand;
@@ -25,7 +26,7 @@ class DisableKeyCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new DisableKeyCommand($this->apiKeyService)); $this->commandTester = $this->testerForCommand(new DisableKeyCommand($this->apiKeyService));
} }
/** @test */ #[Test]
public function providedApiKeyIsDisabled(): void public function providedApiKeyIsDisabled(): void
{ {
$apiKey = 'abcd1234'; $apiKey = 'abcd1234';
@@ -39,7 +40,7 @@ class DisableKeyCommandTest extends TestCase
self::assertStringContainsString('API key "abcd1234" properly disabled', $output); self::assertStringContainsString('API key "abcd1234" properly disabled', $output);
} }
/** @test */ #[Test]
public function errorIsReturnedIfServiceThrowsException(): void public function errorIsReturnedIfServiceThrowsException(): void
{ {
$apiKey = 'abcd1234'; $apiKey = 'abcd1234';

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Api; namespace ShlinkioTest\Shlink\CLI\Command\Api;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\ApiKey\RoleResolverInterface; use Shlinkio\Shlink\CLI\ApiKey\RoleResolverInterface;
@@ -32,7 +33,7 @@ class GenerateKeyCommandTest extends TestCase
$this->commandTester = $this->testerForCommand($command); $this->commandTester = $this->testerForCommand($command);
} }
/** @test */ #[Test]
public function noExpirationDateIsDefinedIfNotProvided(): void public function noExpirationDateIsDefinedIfNotProvided(): void
{ {
$this->apiKeyService->expects($this->once())->method('create')->with( $this->apiKeyService->expects($this->once())->method('create')->with(
@@ -46,7 +47,7 @@ class GenerateKeyCommandTest extends TestCase
self::assertStringContainsString('Generated API key: ', $output); self::assertStringContainsString('Generated API key: ', $output);
} }
/** @test */ #[Test]
public function expirationDateIsDefinedIfProvided(): void public function expirationDateIsDefinedIfProvided(): void
{ {
$this->apiKeyService->expects($this->once())->method('create')->with( $this->apiKeyService->expects($this->once())->method('create')->with(
@@ -59,7 +60,7 @@ class GenerateKeyCommandTest extends TestCase
]); ]);
} }
/** @test */ #[Test]
public function nameIsDefinedIfProvided(): void public function nameIsDefinedIfProvided(): void
{ {
$this->apiKeyService->expects($this->once())->method('create')->with( $this->apiKeyService->expects($this->once())->method('create')->with(

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Api; namespace ShlinkioTest\Shlink\CLI\Command\Api;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand; use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand;
@@ -29,10 +31,7 @@ class ListKeysCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new ListKeysCommand($this->apiKeyService)); $this->commandTester = $this->testerForCommand(new ListKeysCommand($this->apiKeyService));
} }
/** #[Test, DataProvider('provideKeysAndOutputs')]
* @test
* @dataProvider provideKeysAndOutputs
*/
public function returnsExpectedOutput(array $keys, bool $enabledOnly, string $expected): void public function returnsExpectedOutput(array $keys, bool $enabledOnly, string $expected): void
{ {
$this->apiKeyService->expects($this->once())->method('listKeys')->with($enabledOnly)->willReturn($keys); $this->apiKeyService->expects($this->once())->method('listKeys')->with($enabledOnly)->willReturn($keys);

View File

@@ -9,6 +9,8 @@ use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\AbstractSchemaManager;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Db\CreateDatabaseCommand; use Shlinkio\Shlink\CLI\Command\Db\CreateDatabaseCommand;
@@ -63,7 +65,7 @@ class CreateDatabaseCommandTest extends TestCase
$this->commandTester = $this->testerForCommand($command); $this->commandTester = $this->testerForCommand($command);
} }
/** @test */ #[Test]
public function successMessageIsPrintedIfDatabaseAlreadyExists(): void public function successMessageIsPrintedIfDatabaseAlreadyExists(): void
{ {
$shlinkDatabase = 'shlink_database'; $shlinkDatabase = 'shlink_database';
@@ -81,7 +83,7 @@ class CreateDatabaseCommandTest extends TestCase
self::assertStringContainsString('Database already exists. Run "db:migrate" command', $output); self::assertStringContainsString('Database already exists. Run "db:migrate" command', $output);
} }
/** @test */ #[Test]
public function databaseIsCreatedIfItDoesNotExist(): void public function databaseIsCreatedIfItDoesNotExist(): void
{ {
$shlinkDatabase = 'shlink_database'; $shlinkDatabase = 'shlink_database';
@@ -96,10 +98,7 @@ class CreateDatabaseCommandTest extends TestCase
$this->commandTester->execute([]); $this->commandTester->execute([]);
} }
/** #[Test, DataProvider('provideEmptyDatabase')]
* @test
* @dataProvider provideEmptyDatabase
*/
public function tablesAreCreatedIfDatabaseIsEmpty(array $tables): void public function tablesAreCreatedIfDatabaseIsEmpty(array $tables): void
{ {
$shlinkDatabase = 'shlink_database'; $shlinkDatabase = 'shlink_database';
@@ -130,7 +129,7 @@ class CreateDatabaseCommandTest extends TestCase
yield 'migrations table' => [[MIGRATIONS_TABLE]]; yield 'migrations table' => [[MIGRATIONS_TABLE]];
} }
/** @test */ #[Test]
public function databaseCheckIsSkippedForSqlite(): void public function databaseCheckIsSkippedForSqlite(): void
{ {
$this->driver->method('getDatabasePlatform')->willReturn($this->createMock(SqlitePlatform::class)); $this->driver->method('getDatabasePlatform')->willReturn($this->createMock(SqlitePlatform::class));

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Db; namespace ShlinkioTest\Shlink\CLI\Command\Db;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand; use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand;
@@ -38,7 +39,7 @@ class MigrateDatabaseCommandTest extends TestCase
$this->commandTester = $this->testerForCommand($command); $this->commandTester = $this->testerForCommand($command);
} }
/** @test */ #[Test]
public function migrationsCommandIsRunWithProperVerbosity(): void public function migrationsCommandIsRunWithProperVerbosity(): void
{ {
$this->processHelper->expects($this->once())->method('run')->with($this->isInstanceOf(OutputInterface::class), [ $this->processHelper->expects($this->once())->method('run')->with($this->isInstanceOf(OutputInterface::class), [

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Domain; namespace ShlinkioTest\Shlink\CLI\Command\Domain;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Domain\DomainRedirectsCommand; use Shlinkio\Shlink\CLI\Command\Domain\DomainRedirectsCommand;
@@ -30,10 +32,7 @@ class DomainRedirectsCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new DomainRedirectsCommand($this->domainService)); $this->commandTester = $this->testerForCommand(new DomainRedirectsCommand($this->domainService));
} }
/** #[Test, DataProvider('provideDomains')]
* @test
* @dataProvider provideDomains
*/
public function onlyPlainQuestionsAreAskedForNewDomainsAndDomainsWithNoRedirects(?Domain $domain): void public function onlyPlainQuestionsAreAskedForNewDomainsAndDomainsWithNoRedirects(?Domain $domain): void
{ {
$domainAuthority = 'my-domain.com'; $domainAuthority = 'my-domain.com';
@@ -66,7 +65,7 @@ class DomainRedirectsCommandTest extends TestCase
yield 'domain without redirects' => [Domain::withAuthority('')]; yield 'domain without redirects' => [Domain::withAuthority('')];
} }
/** @test */ #[Test]
public function offersNewOptionsForDomainsWithExistingRedirects(): void public function offersNewOptionsForDomainsWithExistingRedirects(): void
{ {
$domainAuthority = 'example.com'; $domainAuthority = 'example.com';
@@ -95,7 +94,7 @@ class DomainRedirectsCommandTest extends TestCase
self::assertEquals(3, substr_count($output, 'Remove redirect')); self::assertEquals(3, substr_count($output, 'Remove redirect'));
} }
/** @test */ #[Test]
public function authorityIsRequestedWhenNotProvidedAndNoOtherDomainsExist(): void public function authorityIsRequestedWhenNotProvidedAndNoOtherDomainsExist(): void
{ {
$domainAuthority = 'example.com'; $domainAuthority = 'example.com';
@@ -117,7 +116,7 @@ class DomainRedirectsCommandTest extends TestCase
self::assertStringContainsString('Domain authority for which you want to set specific redirects', $output); self::assertStringContainsString('Domain authority for which you want to set specific redirects', $output);
} }
/** @test */ #[Test]
public function oneOfTheExistingDomainsCanBeSelected(): void public function oneOfTheExistingDomainsCanBeSelected(): void
{ {
$domainAuthority = 'existing-two.com'; $domainAuthority = 'existing-two.com';
@@ -146,7 +145,7 @@ class DomainRedirectsCommandTest extends TestCase
self::assertStringContainsString($domainAuthority, $output); self::assertStringContainsString($domainAuthority, $output);
} }
/** @test */ #[Test]
public function aNewDomainCanBeCreatedEvenIfOthersAlreadyExist(): void public function aNewDomainCanBeCreatedEvenIfOthersAlreadyExist(): void
{ {
$domainAuthority = 'new-domain.com'; $domainAuthority = 'new-domain.com';

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Domain; namespace ShlinkioTest\Shlink\CLI\Command\Domain;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Domain\GetDomainVisitsCommand; use Shlinkio\Shlink\CLI\Command\Domain\GetDomainVisitsCommand;
@@ -37,7 +38,7 @@ class GetDomainVisitsCommandTest extends TestCase
); );
} }
/** @test */ #[Test]
public function outputIsProperlyGenerated(): void public function outputIsProperlyGenerated(): void
{ {
$shortUrl = ShortUrl::createFake(); $shortUrl = ShortUrl::createFake();

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Domain; namespace ShlinkioTest\Shlink\CLI\Command\Domain;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand; use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand;
@@ -29,10 +31,7 @@ class ListDomainsCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new ListDomainsCommand($this->domainService)); $this->commandTester = $this->testerForCommand(new ListDomainsCommand($this->domainService));
} }
/** #[Test, DataProvider('provideInputsAndOutputs')]
* @test
* @dataProvider provideInputsAndOutputs
*/
public function allDomainsAreProperlyPrinted(array $input, string $expectedOutput): void public function allDomainsAreProperlyPrinted(array $input, string $expectedOutput): void
{ {
$bazDomain = Domain::withAuthority('baz.com'); $bazDomain = Domain::withAuthority('baz.com');

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\ShortUrl\CreateShortUrlCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\CreateShortUrlCommand;
@@ -45,7 +47,7 @@ class CreateShortUrlCommandTest extends TestCase
$this->commandTester = $this->testerForCommand($command); $this->commandTester = $this->testerForCommand($command);
} }
/** @test */ #[Test]
public function properShortCodeIsCreatedIfLongUrlIsCorrect(): void public function properShortCodeIsCreatedIfLongUrlIsCorrect(): void
{ {
$shortUrl = ShortUrl::createFake(); $shortUrl = ShortUrl::createFake();
@@ -64,7 +66,7 @@ class CreateShortUrlCommandTest extends TestCase
self::assertStringContainsString('stringified_short_url', $output); self::assertStringContainsString('stringified_short_url', $output);
} }
/** @test */ #[Test]
public function exceptionWhileParsingLongUrlOutputsError(): void public function exceptionWhileParsingLongUrlOutputsError(): void
{ {
$url = 'http://domain.com/invalid'; $url = 'http://domain.com/invalid';
@@ -80,7 +82,7 @@ class CreateShortUrlCommandTest extends TestCase
self::assertStringContainsString('Provided URL http://domain.com/invalid is invalid.', $output); self::assertStringContainsString('Provided URL http://domain.com/invalid is invalid.', $output);
} }
/** @test */ #[Test]
public function providingNonUniqueSlugOutputsError(): void public function providingNonUniqueSlugOutputsError(): void
{ {
$this->urlShortener->expects($this->once())->method('shorten')->withAnyParameters()->willThrowException( $this->urlShortener->expects($this->once())->method('shorten')->withAnyParameters()->willThrowException(
@@ -95,7 +97,7 @@ class CreateShortUrlCommandTest extends TestCase
self::assertStringContainsString('Provided slug "my-slug" is already in use', $output); self::assertStringContainsString('Provided slug "my-slug" is already in use', $output);
} }
/** @test */ #[Test]
public function properlyProcessesProvidedTags(): void public function properlyProcessesProvidedTags(): void
{ {
$shortUrl = ShortUrl::createFake(); $shortUrl = ShortUrl::createFake();
@@ -119,10 +121,7 @@ class CreateShortUrlCommandTest extends TestCase
self::assertStringContainsString('stringified_short_url', $output); self::assertStringContainsString('stringified_short_url', $output);
} }
/** #[Test, DataProvider('provideDomains')]
* @test
* @dataProvider provideDomains
*/
public function properlyProcessesProvidedDomain(array $input, ?string $expectedDomain): void public function properlyProcessesProvidedDomain(array $input, ?string $expectedDomain): void
{ {
$this->urlShortener->expects($this->once())->method('shorten')->with( $this->urlShortener->expects($this->once())->method('shorten')->with(
@@ -147,10 +146,7 @@ class CreateShortUrlCommandTest extends TestCase
yield 'default domain' => [['--domain' => self::DEFAULT_DOMAIN], null]; yield 'default domain' => [['--domain' => self::DEFAULT_DOMAIN], null];
} }
/** #[Test, DataProvider('provideFlags')]
* @test
* @dataProvider provideFlags
*/
public function urlValidationHasExpectedValueBasedOnProvidedFlags(array $options, ?bool $expectedValidateUrl): void public function urlValidationHasExpectedValueBasedOnProvidedFlags(array $options, ?bool $expectedValidateUrl): void
{ {
$shortUrl = ShortUrl::createFake(); $shortUrl = ShortUrl::createFake();

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\ShortUrl\DeleteShortUrlCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\DeleteShortUrlCommand;
@@ -30,7 +32,7 @@ class DeleteShortUrlCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new DeleteShortUrlCommand($this->service)); $this->commandTester = $this->testerForCommand(new DeleteShortUrlCommand($this->service));
} }
/** @test */ #[Test]
public function successMessageIsPrintedIfUrlIsProperlyDeleted(): void public function successMessageIsPrintedIfUrlIsProperlyDeleted(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -48,7 +50,7 @@ class DeleteShortUrlCommandTest extends TestCase
); );
} }
/** @test */ #[Test]
public function invalidShortCodePrintsMessage(): void public function invalidShortCodePrintsMessage(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -64,10 +66,7 @@ class DeleteShortUrlCommandTest extends TestCase
self::assertStringContainsString(sprintf('No URL found with short code "%s"', $shortCode), $output); self::assertStringContainsString(sprintf('No URL found with short code "%s"', $shortCode), $output);
} }
/** #[Test, DataProvider('provideRetryDeleteAnswers')]
* @test
* @dataProvider provideRetryDeleteAnswers
*/
public function deleteIsRetriedWhenThresholdIsReachedAndQuestionIsAccepted( public function deleteIsRetriedWhenThresholdIsReachedAndQuestionIsAccepted(
array $retryAnswer, array $retryAnswer,
int $expectedDeleteCalls, int $expectedDeleteCalls,
@@ -105,7 +104,7 @@ class DeleteShortUrlCommandTest extends TestCase
yield 'answering default to retry' => [[PHP_EOL], 1, 'Short URL was not deleted.']; yield 'answering default to retry' => [[PHP_EOL], 1, 'Short URL was not deleted.'];
} }
/** @test */ #[Test]
public function deleteIsNotRetriedWhenThresholdIsReachedAndQuestionIsDeclined(): void public function deleteIsNotRetriedWhenThresholdIsReachedAndQuestionIsDeclined(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';

View File

@@ -6,6 +6,7 @@ namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\ShortUrl\GetShortUrlVisitsCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\GetShortUrlVisitsCommand;
@@ -39,7 +40,7 @@ class GetShortUrlVisitsCommandTest extends TestCase
$this->commandTester = $this->testerForCommand($command); $this->commandTester = $this->testerForCommand($command);
} }
/** @test */ #[Test]
public function noDateFlagsTriesToListWithoutDateRange(): void public function noDateFlagsTriesToListWithoutDateRange(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -51,7 +52,7 @@ class GetShortUrlVisitsCommandTest extends TestCase
$this->commandTester->execute(['shortCode' => $shortCode]); $this->commandTester->execute(['shortCode' => $shortCode]);
} }
/** @test */ #[Test]
public function providingDateFlagsTheListGetsFiltered(): void public function providingDateFlagsTheListGetsFiltered(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -69,7 +70,7 @@ class GetShortUrlVisitsCommandTest extends TestCase
]); ]);
} }
/** @test */ #[Test]
public function providingInvalidDatesPrintsWarning(): void public function providingInvalidDatesPrintsWarning(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -91,7 +92,7 @@ class GetShortUrlVisitsCommandTest extends TestCase
); );
} }
/** @test */ #[Test]
public function outputIsProperlyGenerated(): void public function outputIsProperlyGenerated(): void
{ {
$visit = Visit::forValidShortUrl(ShortUrl::createFake(), new Visitor('bar', 'foo', '', ''))->locate( $visit = Visit::forValidShortUrl(ShortUrl::createFake(), new Visitor('bar', 'foo', '', ''))->locate(

View File

@@ -6,6 +6,8 @@ namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand;
@@ -41,7 +43,7 @@ class ListShortUrlsCommandTest extends TestCase
$this->commandTester = $this->testerForCommand($command); $this->commandTester = $this->testerForCommand($command);
} }
/** @test */ #[Test]
public function loadingMorePagesCallsListMoreTimes(): void public function loadingMorePagesCallsListMoreTimes(): void
{ {
// The paginator will return more than one page // The paginator will return more than one page
@@ -63,7 +65,7 @@ class ListShortUrlsCommandTest extends TestCase
self::assertStringNotContainsString('Continue with page 5?', $output); self::assertStringNotContainsString('Continue with page 5?', $output);
} }
/** @test */ #[Test]
public function havingMorePagesButAnsweringNoCallsListJustOnce(): void public function havingMorePagesButAnsweringNoCallsListJustOnce(): void
{ {
// The paginator will return more than one page // The paginator will return more than one page
@@ -89,7 +91,7 @@ class ListShortUrlsCommandTest extends TestCase
self::assertStringNotContainsString('Continue with page 3?', $output); self::assertStringNotContainsString('Continue with page 3?', $output);
} }
/** @test */ #[Test]
public function passingPageWillMakeListStartOnThatPage(): void public function passingPageWillMakeListStartOnThatPage(): void
{ {
$page = 5; $page = 5;
@@ -101,10 +103,7 @@ class ListShortUrlsCommandTest extends TestCase
$this->commandTester->execute(['--page' => $page]); $this->commandTester->execute(['--page' => $page]);
} }
/** #[Test, DataProvider('provideOptionalFlags')]
* @test
* @dataProvider provideOptionalFlags
*/
public function provideOptionalFlagsMakesNewColumnsToBeIncluded( public function provideOptionalFlagsMakesNewColumnsToBeIncluded(
array $input, array $input,
array $expectedContents, array $expectedContents,
@@ -174,10 +173,7 @@ class ListShortUrlsCommandTest extends TestCase
]; ];
} }
/** #[Test, DataProvider('provideArgs')]
* @test
* @dataProvider provideArgs
*/
public function serviceIsInvokedWithProvidedArgs( public function serviceIsInvokedWithProvidedArgs(
array $commandArgs, array $commandArgs,
?int $page, ?int $page,
@@ -241,10 +237,7 @@ class ListShortUrlsCommandTest extends TestCase
]; ];
} }
/** #[Test, DataProvider('provideOrderBy')]
* @test
* @dataProvider provideOrderBy
*/
public function orderByIsProperlyComputed(array $commandArgs, ?string $expectedOrderBy): void public function orderByIsProperlyComputed(array $commandArgs, ?string $expectedOrderBy): void
{ {
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([ $this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([
@@ -264,7 +257,7 @@ class ListShortUrlsCommandTest extends TestCase
yield [['--order-by' => 'title-DESC'], 'title-DESC']; yield [['--order-by' => 'title-DESC'], 'title-DESC'];
} }
/** @test */ #[Test]
public function requestingAllElementsWillSetItemsPerPage(): void public function requestingAllElementsWillSetItemsPerPage(): void
{ {
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([ $this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\ShortUrl\ResolveUrlCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\ResolveUrlCommand;
@@ -31,7 +32,7 @@ class ResolveUrlCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new ResolveUrlCommand($this->urlResolver)); $this->commandTester = $this->testerForCommand(new ResolveUrlCommand($this->urlResolver));
} }
/** @test */ #[Test]
public function correctShortCodeResolvesUrl(): void public function correctShortCodeResolvesUrl(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -46,7 +47,7 @@ class ResolveUrlCommandTest extends TestCase
self::assertEquals('Long URL: ' . $expectedUrl . PHP_EOL, $output); self::assertEquals('Long URL: ' . $expectedUrl . PHP_EOL, $output);
} }
/** @test */ #[Test]
public function incorrectShortCodeOutputsErrorMessage(): void public function incorrectShortCodeOutputsErrorMessage(): void
{ {
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain('abc123'); $identifier = ShortUrlIdentifier::fromShortCodeAndDomain('abc123');

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Tag; namespace ShlinkioTest\Shlink\CLI\Command\Tag;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Tag\DeleteTagsCommand; use Shlinkio\Shlink\CLI\Command\Tag\DeleteTagsCommand;
@@ -24,7 +25,7 @@ class DeleteTagsCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new DeleteTagsCommand($this->tagService)); $this->commandTester = $this->testerForCommand(new DeleteTagsCommand($this->tagService));
} }
/** @test */ #[Test]
public function errorIsReturnedWhenNoTagsAreProvided(): void public function errorIsReturnedWhenNoTagsAreProvided(): void
{ {
$this->commandTester->execute([]); $this->commandTester->execute([]);
@@ -33,7 +34,7 @@ class DeleteTagsCommandTest extends TestCase
self::assertStringContainsString('You have to provide at least one tag name', $output); self::assertStringContainsString('You have to provide at least one tag name', $output);
} }
/** @test */ #[Test]
public function serviceIsInvokedOnSuccess(): void public function serviceIsInvokedOnSuccess(): void
{ {
$tagNames = ['foo', 'bar']; $tagNames = ['foo', 'bar'];

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Tag; namespace ShlinkioTest\Shlink\CLI\Command\Tag;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Tag\GetTagVisitsCommand; use Shlinkio\Shlink\CLI\Command\Tag\GetTagVisitsCommand;
@@ -37,7 +38,7 @@ class GetTagVisitsCommandTest extends TestCase
); );
} }
/** @test */ #[Test]
public function outputIsProperlyGenerated(): void public function outputIsProperlyGenerated(): void
{ {
$shortUrl = ShortUrl::createFake(); $shortUrl = ShortUrl::createFake();

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Tag; namespace ShlinkioTest\Shlink\CLI\Command\Tag;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Tag\ListTagsCommand; use Shlinkio\Shlink\CLI\Command\Tag\ListTagsCommand;
@@ -27,7 +28,7 @@ class ListTagsCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new ListTagsCommand($this->tagService)); $this->commandTester = $this->testerForCommand(new ListTagsCommand($this->tagService));
} }
/** @test */ #[Test]
public function noTagsPrintsEmptyMessage(): void public function noTagsPrintsEmptyMessage(): void
{ {
$this->tagService->expects($this->once())->method('tagsInfo')->withAnyParameters()->willReturn( $this->tagService->expects($this->once())->method('tagsInfo')->withAnyParameters()->willReturn(
@@ -40,7 +41,7 @@ class ListTagsCommandTest extends TestCase
self::assertStringContainsString('No tags found', $output); self::assertStringContainsString('No tags found', $output);
} }
/** @test */ #[Test]
public function listOfTagsIsPrinted(): void public function listOfTagsIsPrinted(): void
{ {
$this->tagService->expects($this->once())->method('tagsInfo')->withAnyParameters()->willReturn( $this->tagService->expects($this->once())->method('tagsInfo')->withAnyParameters()->willReturn(

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Tag; namespace ShlinkioTest\Shlink\CLI\Command\Tag;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Tag\RenameTagCommand; use Shlinkio\Shlink\CLI\Command\Tag\RenameTagCommand;
@@ -27,7 +28,7 @@ class RenameTagCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new RenameTagCommand($this->tagService)); $this->commandTester = $this->testerForCommand(new RenameTagCommand($this->tagService));
} }
/** @test */ #[Test]
public function errorIsPrintedIfExceptionIsThrown(): void public function errorIsPrintedIfExceptionIsThrown(): void
{ {
$oldName = 'foo'; $oldName = 'foo';
@@ -45,7 +46,7 @@ class RenameTagCommandTest extends TestCase
self::assertStringContainsString('Tag with name "foo" could not be found', $output); self::assertStringContainsString('Tag with name "foo" could not be found', $output);
} }
/** @test */ #[Test]
public function successIsPrintedIfNoErrorOccurs(): void public function successIsPrintedIfNoErrorOccurs(): void
{ {
$oldName = 'foo'; $oldName = 'foo';

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Visit; namespace ShlinkioTest\Shlink\CLI\Command\Visit;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Visit\DownloadGeoLiteDbCommand; use Shlinkio\Shlink\CLI\Command\Visit\DownloadGeoLiteDbCommand;
@@ -29,10 +31,7 @@ class DownloadGeoLiteDbCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new DownloadGeoLiteDbCommand($this->dbUpdater)); $this->commandTester = $this->testerForCommand(new DownloadGeoLiteDbCommand($this->dbUpdater));
} }
/** #[Test, DataProvider('provideFailureParams')]
* @test
* @dataProvider provideFailureParams
*/
public function showsProperMessageWhenGeoLiteUpdateFails( public function showsProperMessageWhenGeoLiteUpdateFails(
bool $olderDbExists, bool $olderDbExists,
string $expectedMessage, string $expectedMessage,
@@ -75,10 +74,7 @@ class DownloadGeoLiteDbCommandTest extends TestCase
]; ];
} }
/** #[Test, DataProvider('provideSuccessParams')]
* @test
* @dataProvider provideSuccessParams
*/
public function printsExpectedMessageWhenNoErrorOccurs(callable $checkUpdateBehavior, string $expectedMessage): void public function printsExpectedMessageWhenNoErrorOccurs(callable $checkUpdateBehavior, string $expectedMessage): void
{ {
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback( $this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback(

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Visit; namespace ShlinkioTest\Shlink\CLI\Command\Visit;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Visit\GetNonOrphanVisitsCommand; use Shlinkio\Shlink\CLI\Command\Visit\GetNonOrphanVisitsCommand;
@@ -37,7 +38,7 @@ class GetNonOrphanVisitsCommandTest extends TestCase
); );
} }
/** @test */ #[Test]
public function outputIsProperlyGenerated(): void public function outputIsProperlyGenerated(): void
{ {
$shortUrl = ShortUrl::createFake(); $shortUrl = ShortUrl::createFake();

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Visit; namespace ShlinkioTest\Shlink\CLI\Command\Visit;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Visit\GetOrphanVisitsCommand; use Shlinkio\Shlink\CLI\Command\Visit\GetOrphanVisitsCommand;
@@ -30,7 +31,7 @@ class GetOrphanVisitsCommandTest extends TestCase
$this->commandTester = $this->testerForCommand(new GetOrphanVisitsCommand($this->visitsHelper)); $this->commandTester = $this->testerForCommand(new GetOrphanVisitsCommand($this->visitsHelper));
} }
/** @test */ #[Test]
public function outputIsProperlyGenerated(): void public function outputIsProperlyGenerated(): void
{ {
$visit = Visit::forBasePath(new Visitor('bar', 'foo', '', ''))->locate( $visit = Visit::forBasePath(new Visitor('bar', 'foo', '', ''))->locate(

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Visit; namespace ShlinkioTest\Shlink\CLI\Command\Visit;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Command\Visit\DownloadGeoLiteDbCommand; use Shlinkio\Shlink\CLI\Command\Visit\DownloadGeoLiteDbCommand;
@@ -55,10 +57,7 @@ class LocateVisitsCommandTest extends TestCase
$this->commandTester = $this->testerForCommand($command, $this->downloadDbCommand); $this->commandTester = $this->testerForCommand($command, $this->downloadDbCommand);
} }
/** #[Test, DataProvider('provideArgs')]
* @test
* @dataProvider provideArgs
*/
public function expectedSetOfVisitsIsProcessedBasedOnArgs( public function expectedSetOfVisitsIsProcessedBasedOnArgs(
int $expectedUnlocatedCalls, int $expectedUnlocatedCalls,
int $expectedEmptyCalls, int $expectedEmptyCalls,
@@ -107,10 +106,7 @@ class LocateVisitsCommandTest extends TestCase
yield 'all' => [0, 0, 1, true, ['--retry' => true, '--all' => true]]; yield 'all' => [0, 0, 1, true, ['--retry' => true, '--all' => true]];
} }
/** #[Test, DataProvider('provideIgnoredAddresses')]
* @test
* @dataProvider provideIgnoredAddresses
*/
public function localhostAndEmptyAddressesAreIgnored(IpCannotBeLocatedException $e, string $message): void public function localhostAndEmptyAddressesAreIgnored(IpCannotBeLocatedException $e, string $message): void
{ {
$visit = Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance()); $visit = Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance());
@@ -137,7 +133,7 @@ class LocateVisitsCommandTest extends TestCase
yield 'localhost address' => [IpCannotBeLocatedException::forLocalhost(), 'Ignored localhost address']; yield 'localhost address' => [IpCannotBeLocatedException::forLocalhost(), 'Ignored localhost address'];
} }
/** @test */ #[Test]
public function errorWhileLocatingIpIsDisplayed(): void public function errorWhileLocatingIpIsDisplayed(): void
{ {
$visit = Visit::forValidShortUrl(ShortUrl::createFake(), new Visitor('', '', '1.2.3.4', '')); $visit = Visit::forValidShortUrl(ShortUrl::createFake(), new Visitor('', '', '1.2.3.4', ''));
@@ -168,7 +164,7 @@ class LocateVisitsCommandTest extends TestCase
}; };
} }
/** @test */ #[Test]
public function noActionIsPerformedIfLockIsAcquired(): void public function noActionIsPerformedIfLockIsAcquired(): void
{ {
$this->lock->method('acquire')->with($this->isFalse())->willReturn(false); $this->lock->method('acquire')->with($this->isFalse())->willReturn(false);
@@ -186,7 +182,7 @@ class LocateVisitsCommandTest extends TestCase
); );
} }
/** @test */ #[Test]
public function showsProperMessageWhenGeoLiteUpdateFails(): void public function showsProperMessageWhenGeoLiteUpdateFails(): void
{ {
$this->lock->method('acquire')->with($this->isFalse())->willReturn(true); $this->lock->method('acquire')->with($this->isFalse())->willReturn(true);
@@ -199,7 +195,7 @@ class LocateVisitsCommandTest extends TestCase
self::assertStringContainsString('It is not possible to locate visits without a GeoLite2 db file.', $output); self::assertStringContainsString('It is not possible to locate visits without a GeoLite2 db file.', $output);
} }
/** @test */ #[Test]
public function providingAllFlagOnItsOwnDisplaysNotice(): void public function providingAllFlagOnItsOwnDisplaysNotice(): void
{ {
$this->lock->method('acquire')->with($this->isFalse())->willReturn(true); $this->lock->method('acquire')->with($this->isFalse())->willReturn(true);
@@ -211,10 +207,7 @@ class LocateVisitsCommandTest extends TestCase
self::assertStringContainsString('The --all flag has no effect on its own', $output); self::assertStringContainsString('The --all flag has no effect on its own', $output);
} }
/** #[Test, DataProvider('provideAbortInputs')]
* @test
* @dataProvider provideAbortInputs
*/
public function processingAllCancelsCommandIfUserDoesNotActivelyAgreeToConfirmation(array $inputs): void public function processingAllCancelsCommandIfUserDoesNotActivelyAgreeToConfirmation(array $inputs): void
{ {
$this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCodes::EXIT_SUCCESS); $this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCodes::EXIT_SUCCESS);

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI; namespace ShlinkioTest\Shlink\CLI;
use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\ConfigProvider; use Shlinkio\Shlink\CLI\ConfigProvider;
@@ -17,7 +18,7 @@ class ConfigProviderTest extends TestCase
$this->configProvider = new ConfigProvider(); $this->configProvider = new ConfigProvider();
} }
/** @test */ #[Test]
public function configIsProperlyReturned(): void public function configIsProperlyReturned(): void
{ {
$config = ($this->configProvider)(); $config = ($this->configProvider)();

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Exception; namespace ShlinkioTest\Shlink\CLI\Exception;
use Exception; use Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use RuntimeException; use RuntimeException;
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
@@ -12,10 +14,7 @@ use Throwable;
class GeolocationDbUpdateFailedExceptionTest extends TestCase class GeolocationDbUpdateFailedExceptionTest extends TestCase
{ {
/** #[Test, DataProvider('providePrev')]
* @test
* @dataProvider providePrev
*/
public function withOlderDbBuildsException(?Throwable $prev): void public function withOlderDbBuildsException(?Throwable $prev): void
{ {
$e = GeolocationDbUpdateFailedException::withOlderDb($prev); $e = GeolocationDbUpdateFailedException::withOlderDb($prev);
@@ -29,10 +28,7 @@ class GeolocationDbUpdateFailedExceptionTest extends TestCase
self::assertEquals($prev, $e->getPrevious()); self::assertEquals($prev, $e->getPrevious());
} }
/** #[Test, DataProvider('providePrev')]
* @test
* @dataProvider providePrev
*/
public function withoutOlderDbBuildsException(?Throwable $prev): void public function withoutOlderDbBuildsException(?Throwable $prev): void
{ {
$e = GeolocationDbUpdateFailedException::withoutOlderDb($prev); $e = GeolocationDbUpdateFailedException::withoutOlderDb($prev);
@@ -53,7 +49,7 @@ class GeolocationDbUpdateFailedExceptionTest extends TestCase
yield 'Exception' => [new Exception('prev')]; yield 'Exception' => [new Exception('prev')];
} }
/** @test */ #[Test]
public function withInvalidEpochInOldDbBuildsException(): void public function withInvalidEpochInOldDbBuildsException(): void
{ {
$e = GeolocationDbUpdateFailedException::withInvalidEpochInOldDb('foobar'); $e = GeolocationDbUpdateFailedException::withInvalidEpochInOldDb('foobar');

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Exception; namespace ShlinkioTest\Shlink\CLI\Exception;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Exception\InvalidRoleConfigException; use Shlinkio\Shlink\CLI\Exception\InvalidRoleConfigException;
use Shlinkio\Shlink\Rest\ApiKey\Role; use Shlinkio\Shlink\Rest\ApiKey\Role;
@@ -12,7 +13,7 @@ use function sprintf;
class InvalidRoleConfigExceptionTest extends TestCase class InvalidRoleConfigExceptionTest extends TestCase
{ {
/** @test */ #[Test]
public function forDomainOnlyWithDefaultDomainGeneratesExpectedException(): void public function forDomainOnlyWithDefaultDomainGeneratesExpectedException(): void
{ {
$e = InvalidRoleConfigException::forDomainOnlyWithDefaultDomain(); $e = InvalidRoleConfigException::forDomainOnlyWithDefaultDomain();

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Factory; namespace ShlinkioTest\Shlink\CLI\Factory;
use Laminas\ServiceManager\ServiceManager; use Laminas\ServiceManager\ServiceManager;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Factory\ApplicationFactory; use Shlinkio\Shlink\CLI\Factory\ApplicationFactory;
use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Options\AppOptions;
@@ -21,7 +22,7 @@ class ApplicationFactoryTest extends TestCase
$this->factory = new ApplicationFactory(); $this->factory = new ApplicationFactory();
} }
/** @test */ #[Test]
public function allCommandsWhichAreServicesAreAdded(): void public function allCommandsWhichAreServicesAreAdded(): void
{ {
$sm = $this->createServiceManager([ $sm = $this->createServiceManager([

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\CLI\GeoLite;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
use MaxMind\Db\Reader\Metadata; use MaxMind\Db\Reader\Metadata;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
@@ -35,7 +37,7 @@ class GeolocationDbUpdaterTest extends TestCase
$this->lock->method('acquire')->with($this->isTrue())->willReturn(true); $this->lock->method('acquire')->with($this->isTrue())->willReturn(true);
} }
/** @test */ #[Test]
public function exceptionIsThrownWhenOlderDbDoesNotExistAndDownloadFails(): void public function exceptionIsThrownWhenOlderDbDoesNotExistAndDownloadFails(): void
{ {
$mustBeUpdated = fn () => self::assertTrue(true); $mustBeUpdated = fn () => self::assertTrue(true);
@@ -58,10 +60,7 @@ class GeolocationDbUpdaterTest extends TestCase
} }
} }
/** #[Test, DataProvider('provideBigDays')]
* @test
* @dataProvider provideBigDays
*/
public function exceptionIsThrownWhenOlderDbIsTooOldAndDownloadFails(int $days): void public function exceptionIsThrownWhenOlderDbIsTooOldAndDownloadFails(int $days): void
{ {
$prev = new DbUpdateException(''); $prev = new DbUpdateException('');
@@ -92,10 +91,7 @@ class GeolocationDbUpdaterTest extends TestCase
yield [100]; yield [100];
} }
/** #[Test, DataProvider('provideSmallDays')]
* @test
* @dataProvider provideSmallDays
*/
public function databaseIsNotUpdatedIfItIsNewEnough(string|int $buildEpoch): void public function databaseIsNotUpdatedIfItIsNewEnough(string|int $buildEpoch): void
{ {
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(true); $this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(true);
@@ -119,7 +115,7 @@ class GeolocationDbUpdaterTest extends TestCase
return map(range(0, 34), $generateParamsWithTimestamp); return map(range(0, 34), $generateParamsWithTimestamp);
} }
/** @test */ #[Test]
public function exceptionIsThrownWhenCheckingExistingDatabaseWithInvalidBuildEpoch(): void public function exceptionIsThrownWhenCheckingExistingDatabaseWithInvalidBuildEpoch(): void
{ {
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(true); $this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(true);
@@ -151,10 +147,7 @@ class GeolocationDbUpdaterTest extends TestCase
]); ]);
} }
/** #[Test, DataProvider('provideTrackingOptions')]
* @test
* @dataProvider provideTrackingOptions
*/
public function downloadDbIsSkippedIfTrackingIsDisabled(TrackingOptions $options): void public function downloadDbIsSkippedIfTrackingIsDisabled(TrackingOptions $options): void
{ {
$result = $this->geolocationDbUpdater($options)->checkDbUpdate(); $result = $this->geolocationDbUpdater($options)->checkDbUpdate();

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Util; namespace ShlinkioTest\Shlink\CLI\Util;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\CLI\Util\ProcessRunner; use Shlinkio\Shlink\CLI\Util\ProcessRunner;
@@ -34,7 +35,7 @@ class ProcessRunnerTest extends TestCase
$this->runner = new ProcessRunner($this->helper, fn () => $this->process); $this->runner = new ProcessRunner($this->helper, fn () => $this->process);
} }
/** @test */ #[Test]
public function noMessagesAreWrittenWhenOutputIsNotVerbose(): void public function noMessagesAreWrittenWhenOutputIsNotVerbose(): void
{ {
$this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(false); $this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(false);
@@ -50,7 +51,7 @@ class ProcessRunnerTest extends TestCase
$this->runner->run($this->output, []); $this->runner->run($this->output, []);
} }
/** @test */ #[Test]
public function someMessagesAreWrittenWhenOutputIsVerbose(): void public function someMessagesAreWrittenWhenOutputIsVerbose(): void
{ {
$this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(true); $this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(true);
@@ -66,7 +67,7 @@ class ProcessRunnerTest extends TestCase
$this->runner->run($this->output, []); $this->runner->run($this->output, []);
} }
/** @test */ #[Test]
public function wrapsCallbackWhenOutputIsDebug(): void public function wrapsCallbackWhenOutputIsDebug(): void
{ {
$this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(false); $this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(false);

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Util; namespace ShlinkioTest\Shlink\CLI\Util;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use ReflectionObject; use ReflectionObject;
@@ -23,7 +24,7 @@ class ShlinkTableTest extends TestCase
$this->shlinkTable = ShlinkTable::fromBaseTable($this->baseTable); $this->shlinkTable = ShlinkTable::fromBaseTable($this->baseTable);
} }
/** @test */ #[Test]
public function renderMakesTableToBeRenderedWithProvidedInfo(): void public function renderMakesTableToBeRenderedWithProvidedInfo(): void
{ {
$headers = []; $headers = [];
@@ -43,7 +44,7 @@ class ShlinkTableTest extends TestCase
$this->shlinkTable->render($headers, $rows, $footerTitle, $headerTitle); $this->shlinkTable->render($headers, $rows, $footerTitle, $headerTitle);
} }
/** @test */ #[Test]
public function newTableIsCreatedForFactoryMethod(): void public function newTableIsCreatedForFactoryMethod(): void
{ {
$instance = ShlinkTable::default($this->createMock(OutputInterface::class)); $instance = ShlinkTable::default($this->createMock(OutputInterface::class));

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Core\Action; namespace ShlinkioApiTest\Shlink\Core\Action;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase; use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
use const ShlinkioTest\Shlink\ANDROID_USER_AGENT; use const ShlinkioTest\Shlink\ANDROID_USER_AGENT;
@@ -12,10 +14,7 @@ use const ShlinkioTest\Shlink\IOS_USER_AGENT;
class RedirectTest extends ApiTestCase class RedirectTest extends ApiTestCase
{ {
/** #[Test, DataProvider('provideUserAgents')]
* @test
* @dataProvider provideUserAgents
*/
public function properRedirectHappensBasedOnUserAgent(?string $userAgent, string $expectedRedirect): void public function properRedirectHappensBasedOnUserAgent(?string $userAgent, string $expectedRedirect): void
{ {
$response = $this->callShortUrl('def456', $userAgent); $response = $this->callShortUrl('def456', $userAgent);

View File

@@ -6,6 +6,7 @@ namespace ShlinkioDbTest\Shlink\Core\Domain\Repository;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\Core\Config\NotFoundRedirects; use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Entity\Domain;
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository; use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository;
@@ -26,7 +27,7 @@ class DomainRepositoryTest extends DatabaseTestCase
$this->repo = $this->getEntityManager()->getRepository(Domain::class); $this->repo = $this->getEntityManager()->getRepository(Domain::class);
} }
/** @test */ #[Test]
public function expectedDomainsAreFoundWhenNoApiKeyIsInvolved(): void public function expectedDomainsAreFoundWhenNoApiKeyIsInvolved(): void
{ {
$fooDomain = Domain::withAuthority('foo.com'); $fooDomain = Domain::withAuthority('foo.com');
@@ -61,7 +62,7 @@ class DomainRepositoryTest extends DatabaseTestCase
self::assertTrue($this->repo->domainExists('detached.com')); self::assertTrue($this->repo->domainExists('detached.com'));
} }
/** @test */ #[Test]
public function expectedDomainsAreFoundWhenApiKeyIsProvided(): void public function expectedDomainsAreFoundWhenApiKeyIsProvided(): void
{ {
$authorApiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forAuthoredShortUrls())); $authorApiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forAuthoredShortUrls()));

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioDbTest\Shlink\Core\ShortUrl\Repository; namespace ShlinkioDbTest\Shlink\Core\ShortUrl\Repository;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
use Shlinkio\Shlink\Core\ShortUrl\Repository\CrawlableShortCodesQuery; use Shlinkio\Shlink\Core\ShortUrl\Repository\CrawlableShortCodesQuery;
@@ -19,7 +20,7 @@ class CrawlableShortCodesQueryTest extends DatabaseTestCase
$this->query = new CrawlableShortCodesQuery($em, $em->getClassMetadata(ShortUrl::class)); $this->query = new CrawlableShortCodesQuery($em, $em->getClassMetadata(ShortUrl::class));
} }
/** @test */ #[Test]
public function invokingQueryReturnsExpectedResult(): void public function invokingQueryReturnsExpectedResult(): void
{ {
$createShortUrl = fn (bool $crawlable) => ShortUrl::create( $createShortUrl = fn (bool $crawlable) => ShortUrl::create(

View File

@@ -6,6 +6,7 @@ namespace ShlinkioDbTest\Shlink\Core\ShortUrl\Repository;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\Attributes\Test;
use ReflectionObject; use ReflectionObject;
use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Model\Ordering; use Shlinkio\Shlink\Core\Model\Ordering;
@@ -37,7 +38,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
$this->relationResolver = new PersistenceShortUrlRelationResolver($em); $this->relationResolver = new PersistenceShortUrlRelationResolver($em);
} }
/** @test */ #[Test]
public function countListReturnsProperNumberOfResults(): void public function countListReturnsProperNumberOfResults(): void
{ {
$count = 5; $count = 5;
@@ -49,7 +50,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
self::assertEquals($count, $this->repo->countList(new ShortUrlsCountFiltering())); self::assertEquals($count, $this->repo->countList(new ShortUrlsCountFiltering()));
} }
/** @test */ #[Test]
public function findListProperlyFiltersResult(): void public function findListProperlyFiltersResult(): void
{ {
$foo = ShortUrl::create( $foo = ShortUrl::create(
@@ -143,7 +144,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function findListProperlyMapsFieldNamesToColumnNamesWhenOrdering(): void public function findListProperlyMapsFieldNamesToColumnNamesWhenOrdering(): void
{ {
$urls = ['a', 'z', 'c', 'b']; $urls = ['a', 'z', 'c', 'b'];
@@ -164,7 +165,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
self::assertEquals('z', $result[3]->getLongUrl()); self::assertEquals('z', $result[3]->getLongUrl());
} }
/** @test */ #[Test]
public function findListReturnsOnlyThoseWithMatchingTags(): void public function findListReturnsOnlyThoseWithMatchingTags(): void
{ {
$shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([ $shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([
@@ -273,7 +274,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function findListReturnsOnlyThoseWithMatchingDomains(): void public function findListReturnsOnlyThoseWithMatchingDomains(): void
{ {
$shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([ $shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([
@@ -309,7 +310,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
self::assertCount(0, $this->repo->findList($buildFiltering('no results'))); self::assertCount(0, $this->repo->findList($buildFiltering('no results')));
} }
/** @test */ #[Test]
public function findListReturnsOnlyThoseWithoutExcludedUrls(): void public function findListReturnsOnlyThoseWithoutExcludedUrls(): void
{ {
$shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([ $shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioDbTest\Shlink\Core\ShortUrl\Repository; namespace ShlinkioDbTest\Shlink\Core\ShortUrl\Repository;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Entity\Domain;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
@@ -30,7 +31,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager()); $this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager());
} }
/** @test */ #[Test]
public function findOneWithDomainFallbackReturnsProperData(): void public function findOneWithDomainFallbackReturnsProperData(): void
{ {
$regularOne = ShortUrl::create(ShortUrlCreation::fromRawData(['customSlug' => 'Foo', 'longUrl' => 'foo'])); $regularOne = ShortUrl::create(ShortUrlCreation::fromRawData(['customSlug' => 'Foo', 'longUrl' => 'foo']));
@@ -97,7 +98,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function shortCodeIsInUseLooksForShortUrlInProperSetOfTables(): void public function shortCodeIsInUseLooksForShortUrlInProperSetOfTables(): void
{ {
$shortUrlWithoutDomain = ShortUrl::create( $shortUrlWithoutDomain = ShortUrl::create(
@@ -126,7 +127,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function findOneLooksForShortUrlInProperSetOfTables(): void public function findOneLooksForShortUrlInProperSetOfTables(): void
{ {
$shortUrlWithoutDomain = ShortUrl::create( $shortUrlWithoutDomain = ShortUrl::create(
@@ -153,7 +154,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function findOneMatchingReturnsNullForNonExistingShortUrls(): void public function findOneMatchingReturnsNullForNonExistingShortUrls(): void
{ {
self::assertNull($this->repo->findOneMatching(ShortUrlCreation::fromRawData(['longUrl' => 'foobar']))); self::assertNull($this->repo->findOneMatching(ShortUrlCreation::fromRawData(['longUrl' => 'foobar'])));
@@ -168,7 +169,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
]))); ])));
} }
/** @test */ #[Test]
public function findOneMatchingAppliesProperConditions(): void public function findOneMatchingAppliesProperConditions(): void
{ {
$start = Chronos::parse('2020-03-05 20:18:30'); $start = Chronos::parse('2020-03-05 20:18:30');
@@ -237,7 +238,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
); );
} }
/** @test */ #[Test]
public function findOneMatchingReturnsOldestOneWhenThereAreMultipleMatches(): void public function findOneMatchingReturnsOldestOneWhenThereAreMultipleMatches(): void
{ {
$start = Chronos::parse('2020-03-05 20:18:30'); $start = Chronos::parse('2020-03-05 20:18:30');
@@ -265,7 +266,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
self::assertNotSame($shortUrl3, $result); self::assertNotSame($shortUrl3, $result);
} }
/** @test */ #[Test]
public function findOneMatchingAppliesProvidedApiKeyConditions(): void public function findOneMatchingAppliesProvidedApiKeyConditions(): void
{ {
$start = Chronos::parse('2020-03-05 20:18:30'); $start = Chronos::parse('2020-03-05 20:18:30');
@@ -391,7 +392,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
); );
} }
/** @test */ #[Test]
public function importedShortUrlsAreFoundWhenExpected(): void public function importedShortUrlsAreFoundWhenExpected(): void
{ {
$buildImported = static fn (string $shortCode, ?String $domain = null) => $buildImported = static fn (string $shortCode, ?String $domain = null) =>

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioDbTest\Shlink\Core\Tag\Paginator\Adapter; namespace ShlinkioDbTest\Shlink\Core\Tag\Paginator\Adapter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\Core\Tag\Entity\Tag; use Shlinkio\Shlink\Core\Tag\Entity\Tag;
use Shlinkio\Shlink\Core\Tag\Model\TagsParams; use Shlinkio\Shlink\Core\Tag\Model\TagsParams;
use Shlinkio\Shlink\Core\Tag\Paginator\Adapter\TagsPaginatorAdapter; use Shlinkio\Shlink\Core\Tag\Paginator\Adapter\TagsPaginatorAdapter;
@@ -24,9 +26,8 @@ class TagsPaginatorAdapterTest extends DatabaseTestCase
/** /**
* @param int<0, max> $offset * @param int<0, max> $offset
* @param int<0, max> $length * @param int<0, max> $length
* @test
* @dataProvider provideFilters
*/ */
#[Test, DataProvider('provideFilters')]
public function expectedListOfTagsIsReturned( public function expectedListOfTagsIsReturned(
?string $searchTerm, ?string $searchTerm,
?string $orderBy, ?string $orderBy,

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioDbTest\Shlink\Core\Tag\Repository; namespace ShlinkioDbTest\Shlink\Core\Tag\Repository;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Entity\Domain;
use Shlinkio\Shlink\Core\Model\Ordering; use Shlinkio\Shlink\Core\Model\Ordering;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
@@ -34,13 +36,13 @@ class TagRepositoryTest extends DatabaseTestCase
$this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager()); $this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager());
} }
/** @test */ #[Test]
public function deleteByNameDoesNothingWhenEmptyListIsProvided(): void public function deleteByNameDoesNothingWhenEmptyListIsProvided(): void
{ {
self::assertEquals(0, $this->repo->deleteByName([])); self::assertEquals(0, $this->repo->deleteByName([]));
} }
/** @test */ #[Test]
public function allTagsWhichMatchNameAreDeleted(): void public function allTagsWhichMatchNameAreDeleted(): void
{ {
$names = ['foo', 'bar', 'baz']; $names = ['foo', 'bar', 'baz'];
@@ -54,10 +56,7 @@ class TagRepositoryTest extends DatabaseTestCase
self::assertEquals(2, $this->repo->deleteByName($toDelete)); self::assertEquals(2, $this->repo->deleteByName($toDelete));
} }
/** #[Test, DataProvider('provideFilters')]
* @test
* @dataProvider provideFilters
*/
public function properTagsInfoIsReturned(?TagsListFiltering $filtering, array $expectedList): void public function properTagsInfoIsReturned(?TagsListFiltering $filtering, array $expectedList): void
{ {
$names = ['foo', 'bar', 'baz', 'another']; $names = ['foo', 'bar', 'baz', 'another'];
@@ -221,7 +220,7 @@ class TagRepositoryTest extends DatabaseTestCase
]]; ]];
} }
/** @test */ #[Test]
public function tagExistsReturnsExpectedResultBasedOnApiKey(): void public function tagExistsReturnsExpectedResultBasedOnApiKey(): void
{ {
$domain = Domain::withAuthority('foo.com'); $domain = Domain::withAuthority('foo.com');

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioDbTest\Shlink\Core\Visit\Repository; namespace ShlinkioDbTest\Shlink\Core\Visit\Repository;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Entity\Visit;
use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation; use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation;
@@ -25,10 +27,7 @@ class VisitLocationRepositoryTest extends DatabaseTestCase
$this->repo = new VisitLocationRepository($em, $em->getClassMetadata(Visit::class)); $this->repo = new VisitLocationRepository($em, $em->getClassMetadata(Visit::class));
} }
/** #[Test, DataProvider('provideBlockSize')]
* @test
* @dataProvider provideBlockSize
*/
public function findVisitsReturnsProperVisits(int $blockSize): void public function findVisitsReturnsProperVisits(int $blockSize): void
{ {
$shortUrl = ShortUrl::createFake(); $shortUrl = ShortUrl::createFake();

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioDbTest\Shlink\Core\Visit\Repository; namespace ShlinkioDbTest\Shlink\Core\Visit\Repository;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\Attributes\Test;
use ReflectionObject; use ReflectionObject;
use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Entity\Domain;
@@ -40,7 +41,7 @@ class VisitRepositoryTest extends DatabaseTestCase
$this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager()); $this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager());
} }
/** @test */ #[Test]
public function findVisitsByShortCodeReturnsProperData(): void public function findVisitsByShortCodeReturnsProperData(): void
{ {
[$shortCode, $domain] = $this->createShortUrlsAndVisits(); [$shortCode, $domain] = $this->createShortUrlsAndVisits();
@@ -89,7 +90,7 @@ class VisitRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function countVisitsByShortCodeReturnsProperData(): void public function countVisitsByShortCodeReturnsProperData(): void
{ {
[$shortCode, $domain] = $this->createShortUrlsAndVisits(); [$shortCode, $domain] = $this->createShortUrlsAndVisits();
@@ -126,7 +127,7 @@ class VisitRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function findVisitsByShortCodeReturnsProperDataWhenUsingAPiKeys(): void public function findVisitsByShortCodeReturnsProperDataWhenUsingAPiKeys(): void
{ {
$adminApiKey = ApiKey::create(); $adminApiKey = ApiKey::create();
@@ -158,7 +159,7 @@ class VisitRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function findVisitsByTagReturnsProperData(): void public function findVisitsByTagReturnsProperData(): void
{ {
$foo = 'foo'; $foo = 'foo';
@@ -183,7 +184,7 @@ class VisitRepositoryTest extends DatabaseTestCase
))); )));
} }
/** @test */ #[Test]
public function countVisitsByTagReturnsProperData(): void public function countVisitsByTagReturnsProperData(): void
{ {
$foo = 'foo'; $foo = 'foo';
@@ -205,7 +206,7 @@ class VisitRepositoryTest extends DatabaseTestCase
))); )));
} }
/** @test */ #[Test]
public function findVisitsByDomainReturnsProperData(): void public function findVisitsByDomainReturnsProperData(): void
{ {
$this->createShortUrlsAndVisits('s.test'); $this->createShortUrlsAndVisits('s.test');
@@ -229,7 +230,7 @@ class VisitRepositoryTest extends DatabaseTestCase
))); )));
} }
/** @test */ #[Test]
public function countVisitsByDomainReturnsProperData(): void public function countVisitsByDomainReturnsProperData(): void
{ {
$this->createShortUrlsAndVisits('s.test'); $this->createShortUrlsAndVisits('s.test');
@@ -253,7 +254,7 @@ class VisitRepositoryTest extends DatabaseTestCase
))); )));
} }
/** @test */ #[Test]
public function countVisitsReturnsExpectedResultBasedOnApiKey(): void public function countVisitsReturnsExpectedResultBasedOnApiKey(): void
{ {
$domain = Domain::withAuthority('foo.com'); $domain = Domain::withAuthority('foo.com');
@@ -316,7 +317,7 @@ class VisitRepositoryTest extends DatabaseTestCase
self::assertEquals(3, $this->repo->countOrphanVisits(new VisitsCountFiltering(null, true))); self::assertEquals(3, $this->repo->countOrphanVisits(new VisitsCountFiltering(null, true)));
} }
/** @test */ #[Test]
public function findOrphanVisitsReturnsExpectedResult(): void public function findOrphanVisitsReturnsExpectedResult(): void
{ {
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'longUrl'])); $shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'longUrl']));
@@ -365,7 +366,7 @@ class VisitRepositoryTest extends DatabaseTestCase
))); )));
} }
/** @test */ #[Test]
public function countOrphanVisitsReturnsExpectedResult(): void public function countOrphanVisitsReturnsExpectedResult(): void
{ {
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'longUrl'])); $shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'longUrl']));
@@ -402,7 +403,7 @@ class VisitRepositoryTest extends DatabaseTestCase
)); ));
} }
/** @test */ #[Test]
public function findNonOrphanVisitsReturnsExpectedResult(): void public function findNonOrphanVisitsReturnsExpectedResult(): void
{ {
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => '1'])); $shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => '1']));
@@ -445,7 +446,7 @@ class VisitRepositoryTest extends DatabaseTestCase
self::assertCount(5, $this->repo->findNonOrphanVisits(new VisitsListFiltering(null, false, null, 5, 5))); self::assertCount(5, $this->repo->findNonOrphanVisits(new VisitsListFiltering(null, false, null, 5, 5)));
} }
/** @test */ #[Test]
public function findMostRecentOrphanVisitReturnsExpectedVisit(): void public function findMostRecentOrphanVisitReturnsExpectedVisit(): void
{ {
$this->assertNull($this->repo->findMostRecentOrphanVisit()); $this->assertNull($this->repo->findMostRecentOrphanVisit());

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Action; namespace ShlinkioTest\Shlink\Core\Action;
use Laminas\Diactoros\ServerRequest; use Laminas\Diactoros\ServerRequest;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
@@ -29,7 +30,7 @@ class PixelActionTest extends TestCase
$this->action = new PixelAction($this->urlResolver, $this->requestTracker); $this->action = new PixelAction($this->urlResolver, $this->requestTracker);
} }
/** @test */ #[Test]
public function imageIsReturned(): void public function imageIsReturned(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Core\Action;
use Laminas\Diactoros\Response; use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequest; use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@@ -37,7 +39,7 @@ class QrCodeActionTest extends TestCase
$this->urlResolver = $this->createMock(ShortUrlResolverInterface::class); $this->urlResolver = $this->createMock(ShortUrlResolverInterface::class);
} }
/** @test */ #[Test]
public function aNotFoundShortCodeWillDelegateIntoNextMiddleware(): void public function aNotFoundShortCodeWillDelegateIntoNextMiddleware(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -50,7 +52,7 @@ class QrCodeActionTest extends TestCase
$this->action()->process((new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate); $this->action()->process((new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate);
} }
/** @test */ #[Test]
public function aCorrectRequestReturnsTheQrCodeResponse(): void public function aCorrectRequestReturnsTheQrCodeResponse(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -66,10 +68,7 @@ class QrCodeActionTest extends TestCase
self::assertEquals(200, $resp->getStatusCode()); self::assertEquals(200, $resp->getStatusCode());
} }
/** #[Test, DataProvider('provideQueries')]
* @test
* @dataProvider provideQueries
*/
public function imageIsReturnedWithExpectedContentTypeBasedOnProvidedFormat( public function imageIsReturnedWithExpectedContentTypeBasedOnProvidedFormat(
string $defaultFormat, string $defaultFormat,
array $query, array $query,
@@ -99,10 +98,7 @@ class QrCodeActionTest extends TestCase
yield 'unsupported format, svg default' => ['svg', ['format' => 'jpg'], 'image/svg+xml']; yield 'unsupported format, svg default' => ['svg', ['format' => 'jpg'], 'image/svg+xml'];
} }
/** #[Test, DataProvider('provideRequestsWithSize')]
* @test
* @dataProvider provideRequestsWithSize
*/
public function imageIsReturnedWithExpectedSize( public function imageIsReturnedWithExpectedSize(
QrCodeOptions $defaultOptions, QrCodeOptions $defaultOptions,
ServerRequestInterface $req, ServerRequestInterface $req,
@@ -188,10 +184,7 @@ class QrCodeActionTest extends TestCase
]; ];
} }
/** #[Test, DataProvider('provideRoundBlockSize')]
* @test
* @dataProvider provideRoundBlockSize
*/
public function imageCanRemoveExtraMarginWhenBlockRoundIsDisabled( public function imageCanRemoveExtraMarginWhenBlockRoundIsDisabled(
QrCodeOptions $defaultOptions, QrCodeOptions $defaultOptions,
?string $roundBlockSize, ?string $roundBlockSize,

View File

@@ -6,6 +6,7 @@ namespace ShlinkioTest\Shlink\Core\Action;
use Laminas\Diactoros\Response; use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequest; use Laminas\Diactoros\ServerRequest;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
@@ -44,7 +45,7 @@ class RedirectActionTest extends TestCase
); );
} }
/** @test */ #[Test]
public function redirectionIsPerformedToLongUrl(): void public function redirectionIsPerformedToLongUrl(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
@@ -64,7 +65,7 @@ class RedirectActionTest extends TestCase
self::assertSame($expectedResp, $response); self::assertSame($expectedResp, $response);
} }
/** @test */ #[Test]
public function nextMiddlewareIsInvokedIfLongUrlIsNotFound(): void public function nextMiddlewareIsInvokedIfLongUrlIsNotFound(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Action; namespace ShlinkioTest\Shlink\Core\Action;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Action\RobotsAction; use Shlinkio\Shlink\Core\Action\RobotsAction;
@@ -21,10 +23,7 @@ class RobotsActionTest extends TestCase
$this->action = new RobotsAction($this->helper); $this->action = new RobotsAction($this->helper);
} }
/** #[Test, DataProvider('provideShortCodes')]
* @test
* @dataProvider provideShortCodes
*/
public function buildsRobotsLinesFromCrawlableShortCodes(array $shortCodes, string $expected): void public function buildsRobotsLinesFromCrawlableShortCodes(array $shortCodes, string $expected): void
{ {
$this->helper $this->helper

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config; namespace ShlinkioTest\Shlink\Core\Config;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\EmptyNotFoundRedirectConfig; use Shlinkio\Shlink\Core\Config\EmptyNotFoundRedirectConfig;
@@ -16,7 +17,7 @@ class EmptyNotFoundRedirectConfigTest extends TestCase
$this->redirectsConfig = new EmptyNotFoundRedirectConfig(); $this->redirectsConfig = new EmptyNotFoundRedirectConfig();
} }
/** @test */ #[Test]
public function allMethodsReturnHardcodedValues(): void public function allMethodsReturnHardcodedValues(): void
{ {
self::assertNull($this->redirectsConfig->invalidShortUrlRedirect()); self::assertNull($this->redirectsConfig->invalidShortUrlRedirect());

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config; namespace ShlinkioTest\Shlink\Core\Config;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\EnvVars; use Shlinkio\Shlink\Core\Config\EnvVars;
@@ -23,10 +25,7 @@ class EnvVarsTest extends TestCase
putenv(EnvVars::DB_NAME->value . '='); putenv(EnvVars::DB_NAME->value . '=');
} }
/** #[Test, DataProvider('provideExistingEnvVars')]
* @test
* @dataProvider provideExistingEnvVars
*/
public function existsInEnvReturnsExpectedValue(EnvVars $envVar, bool $exists): void public function existsInEnvReturnsExpectedValue(EnvVars $envVar, bool $exists): void
{ {
self::assertEquals($exists, $envVar->existsInEnv()); self::assertEquals($exists, $envVar->existsInEnv());
@@ -40,10 +39,7 @@ class EnvVarsTest extends TestCase
yield 'DEFAULT_REGULAR_404_REDIRECT' => [EnvVars::DEFAULT_REGULAR_404_REDIRECT, false]; yield 'DEFAULT_REGULAR_404_REDIRECT' => [EnvVars::DEFAULT_REGULAR_404_REDIRECT, false];
} }
/** #[Test, DataProvider('provideEnvVarsValues')]
* @test
* @dataProvider provideEnvVarsValues
*/
public function expectedValueIsLoadedFromEnv(EnvVars $envVar, mixed $expected, mixed $default): void public function expectedValueIsLoadedFromEnv(EnvVars $envVar, mixed $expected, mixed $default): void
{ {
self::assertEquals($expected, $envVar->loadFromEnv($default)); self::assertEquals($expected, $envVar->loadFromEnv($default));

View File

@@ -9,6 +9,8 @@ use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\Uri; use Laminas\Diactoros\Uri;
use Mezzio\Router\Route; use Mezzio\Router\Route;
use Mezzio\Router\RouteResult; use Mezzio\Router\RouteResult;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@@ -33,10 +35,7 @@ class NotFoundRedirectResolverTest extends TestCase
$this->resolver = new NotFoundRedirectResolver($this->helper, new NullLogger()); $this->resolver = new NotFoundRedirectResolver($this->helper, new NullLogger());
} }
/** #[Test, DataProvider('provideRedirects')]
* @test
* @dataProvider provideRedirects
*/
public function expectedRedirectionIsReturnedDependingOnTheCase( public function expectedRedirectionIsReturnedDependingOnTheCase(
UriInterface $uri, UriInterface $uri,
NotFoundType $notFoundType, NotFoundType $notFoundType,
@@ -113,7 +112,7 @@ class NotFoundRedirectResolverTest extends TestCase
]; ];
} }
/** @test */ #[Test]
public function noResponseIsReturnedIfNoConditionsMatch(): void public function noResponseIsReturnedIfNoConditionsMatch(): void
{ {
$notFoundType = self::notFoundType(self::requestForRoute('foo')); $notFoundType = self::notFoundType(self::requestForRoute('foo'));

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config\PostProcessor; namespace ShlinkioTest\Shlink\Core\Config\PostProcessor;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\PostProcessor\BasePathPrefixer; use Shlinkio\Shlink\Core\Config\PostProcessor\BasePathPrefixer;
@@ -16,10 +18,7 @@ class BasePathPrefixerTest extends TestCase
$this->prefixer = new BasePathPrefixer(); $this->prefixer = new BasePathPrefixer();
} }
/** #[Test, DataProvider('provideConfig')]
* @test
* @dataProvider provideConfig
*/
public function parsesConfigAsExpected( public function parsesConfigAsExpected(
array $originalConfig, array $originalConfig,
array $expectedRoutes, array $expectedRoutes,

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config\PostProcessor; namespace ShlinkioTest\Shlink\Core\Config\PostProcessor;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\PostProcessor\MultiSegmentSlugProcessor; use Shlinkio\Shlink\Core\Config\PostProcessor\MultiSegmentSlugProcessor;
@@ -16,10 +18,7 @@ class MultiSegmentSlugProcessorTest extends TestCase
$this->processor = new MultiSegmentSlugProcessor(); $this->processor = new MultiSegmentSlugProcessor();
} }
/** #[Test, DataProvider('provideConfigs')]
* @test
* @dataProvider provideConfigs
*/
public function parsesRoutesAsExpected(array $config, array $expectedRoutes): void public function parsesRoutesAsExpected(array $config, array $expectedRoutes): void
{ {
self::assertEquals($expectedRoutes, ($this->processor)($config)['routes'] ?? []); self::assertEquals($expectedRoutes, ($this->processor)($config)['routes'] ?? []);

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config\PostProcessor; namespace ShlinkioTest\Shlink\Core\Config\PostProcessor;
use Mezzio\Router\Route; use Mezzio\Router\Route;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Action\RedirectAction; use Shlinkio\Shlink\Core\Action\RedirectAction;
use Shlinkio\Shlink\Core\Config\PostProcessor\ShortUrlMethodsProcessor; use Shlinkio\Shlink\Core\Config\PostProcessor\ShortUrlMethodsProcessor;
@@ -18,10 +20,7 @@ class ShortUrlMethodsProcessorTest extends TestCase
$this->processor = new ShortUrlMethodsProcessor(); $this->processor = new ShortUrlMethodsProcessor();
} }
/** #[Test, DataProvider('provideConfigs')]
* @test
* @dataProvider provideConfigs
*/
public function onlyFirstRouteIdentifiedAsRedirectIsEditedWithProperAllowedMethods( public function onlyFirstRouteIdentifiedAsRedirectIsEditedWithProperAllowedMethods(
array $config, array $config,
?array $expectedRoutes, ?array $expectedRoutes,

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core; namespace ShlinkioTest\Shlink\Core;
use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\ConfigProvider; use Shlinkio\Shlink\Core\ConfigProvider;
@@ -17,7 +18,7 @@ class ConfigProviderTest extends TestCase
$this->configProvider = new ConfigProvider(); $this->configProvider = new ConfigProvider();
} }
/** @test */ #[Test]
public function properConfigIsReturned(): void public function properConfigIsReturned(): void
{ {
$config = ($this->configProvider)(); $config = ($this->configProvider)();

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Crawling; namespace ShlinkioTest\Shlink\Core\Crawling;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Crawling\CrawlingHelper; use Shlinkio\Shlink\Core\Crawling\CrawlingHelper;
@@ -20,7 +21,7 @@ class CrawlingHelperTest extends TestCase
$this->helper = new CrawlingHelper($this->query); $this->helper = new CrawlingHelper($this->query);
} }
/** @test */ #[Test]
public function listCrawlableShortCodesDelegatesIntoRepository(): void public function listCrawlableShortCodesDelegatesIntoRepository(): void
{ {
$this->query->expects($this->once())->method('__invoke')->willReturn([]); $this->query->expects($this->once())->method('__invoke')->willReturn([]);

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Domain; namespace ShlinkioTest\Shlink\Core\Domain;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\EmptyNotFoundRedirectConfig; use Shlinkio\Shlink\Core\Config\EmptyNotFoundRedirectConfig;
@@ -29,10 +31,7 @@ class DomainServiceTest extends TestCase
$this->domainService = new DomainService($this->em, 'default.com'); $this->domainService = new DomainService($this->em, 'default.com');
} }
/** #[Test, DataProvider('provideExcludedDomains')]
* @test
* @dataProvider provideExcludedDomains
*/
public function listDomainsDelegatesIntoRepository(array $domains, array $expectedResult, ?ApiKey $apiKey): void public function listDomainsDelegatesIntoRepository(array $domains, array $expectedResult, ?ApiKey $apiKey): void
{ {
$repo = $this->createMock(DomainRepositoryInterface::class); $repo = $this->createMock(DomainRepositoryInterface::class);
@@ -102,7 +101,7 @@ class DomainServiceTest extends TestCase
]; ];
} }
/** @test */ #[Test]
public function getDomainThrowsExceptionWhenDomainIsNotFound(): void public function getDomainThrowsExceptionWhenDomainIsNotFound(): void
{ {
$this->em->expects($this->once())->method('find')->with(Domain::class, '123')->willReturn(null); $this->em->expects($this->once())->method('find')->with(Domain::class, '123')->willReturn(null);
@@ -112,7 +111,7 @@ class DomainServiceTest extends TestCase
$this->domainService->getDomain('123'); $this->domainService->getDomain('123');
} }
/** @test */ #[Test]
public function getDomainReturnsEntityWhenFound(): void public function getDomainReturnsEntityWhenFound(): void
{ {
$domain = Domain::withAuthority(''); $domain = Domain::withAuthority('');
@@ -123,10 +122,7 @@ class DomainServiceTest extends TestCase
self::assertSame($domain, $result); self::assertSame($domain, $result);
} }
/** #[Test, DataProvider('provideFoundDomains')]
* @test
* @dataProvider provideFoundDomains
*/
public function getOrCreateAlwaysPersistsDomain(?Domain $foundDomain, ?ApiKey $apiKey): void public function getOrCreateAlwaysPersistsDomain(?Domain $foundDomain, ?ApiKey $apiKey): void
{ {
$authority = 'example.com'; $authority = 'example.com';
@@ -145,7 +141,7 @@ class DomainServiceTest extends TestCase
} }
} }
/** @test */ #[Test]
public function getOrCreateThrowsExceptionForApiKeysWithDomainRole(): void public function getOrCreateThrowsExceptionForApiKeysWithDomainRole(): void
{ {
$authority = 'example.com'; $authority = 'example.com';
@@ -163,10 +159,7 @@ class DomainServiceTest extends TestCase
$this->domainService->getOrCreate($authority, $apiKey); $this->domainService->getOrCreate($authority, $apiKey);
} }
/** #[Test, DataProvider('provideFoundDomains')]
* @test
* @dataProvider provideFoundDomains
*/
public function configureNotFoundRedirectsConfiguresFetchedDomain(?Domain $foundDomain, ?ApiKey $apiKey): void public function configureNotFoundRedirectsConfiguresFetchedDomain(?Domain $foundDomain, ?ApiKey $apiKey): void
{ {
$authority = 'example.com'; $authority = 'example.com';

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Core\ErrorHandler;
use Laminas\Diactoros\Response; use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@@ -43,10 +45,7 @@ class NotFoundRedirectHandlerTest extends TestCase
); );
} }
/** #[Test, DataProvider('provideNonRedirectScenarios')]
* @test
* @dataProvider provideNonRedirectScenarios
*/
public function nextIsCalledWhenNoRedirectIsResolved(callable $setUp): void public function nextIsCalledWhenNoRedirectIsResolved(callable $setUp): void
{ {
$expectedResp = new Response(); $expectedResp = new Response();
@@ -95,7 +94,7 @@ class NotFoundRedirectHandlerTest extends TestCase
}]; }];
} }
/** @test */ #[Test]
public function globalRedirectIsUsedIfDomainRedirectIsNotFound(): void public function globalRedirectIsUsedIfDomainRedirectIsNotFound(): void
{ {
$expectedResp = new Response(); $expectedResp = new Response();
@@ -113,7 +112,7 @@ class NotFoundRedirectHandlerTest extends TestCase
self::assertSame($expectedResp, $result); self::assertSame($expectedResp, $result);
} }
/** @test */ #[Test]
public function domainRedirectIsUsedIfFound(): void public function domainRedirectIsUsedIfFound(): void
{ {
$expectedResp = new Response(); $expectedResp = new Response();

View File

@@ -9,6 +9,8 @@ use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\Uri; use Laminas\Diactoros\Uri;
use Mezzio\Router\Route; use Mezzio\Router\Route;
use Mezzio\Router\RouteResult; use Mezzio\Router\RouteResult;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Core\Action\RedirectAction; use Shlinkio\Shlink\Core\Action\RedirectAction;
@@ -32,10 +34,7 @@ class NotFoundTemplateHandlerTest extends TestCase
$this->handler = new NotFoundTemplateHandler($readFile); $this->handler = new NotFoundTemplateHandler($readFile);
} }
/** #[Test, DataProvider('provideTemplates')]
* @test
* @dataProvider provideTemplates
*/
public function properErrorTemplateIsRendered(ServerRequestInterface $request, string $expectedTemplate): void public function properErrorTemplateIsRendered(ServerRequestInterface $request, string $expectedTemplate): void
{ {
$resp = $this->handler->handle($request->withHeader('Accept', 'text/html')); $resp = $this->handler->handle($request->withHeader('Accept', 'text/html'));

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ErrorHandler; namespace ShlinkioTest\Shlink\Core\ErrorHandler;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@@ -32,7 +33,7 @@ class NotFoundTrackerMiddlewareTest extends TestCase
); );
} }
/** @test */ #[Test]
public function delegatesIntoRequestTracker(): void public function delegatesIntoRequestTracker(): void
{ {
$this->handler->expects($this->once())->method('handle')->with($this->request); $this->handler->expects($this->once())->method('handle')->with($this->request);

View File

@@ -7,6 +7,7 @@ namespace ShlinkioTest\Shlink\Core\ErrorHandler;
use Laminas\Diactoros\Response; use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@@ -25,7 +26,7 @@ class NotFoundTypeResolverMiddlewareTest extends TestCase
$this->handler = $this->createMock(RequestHandlerInterface::class); $this->handler = $this->createMock(RequestHandlerInterface::class);
} }
/** @test */ #[Test]
public function notFoundTypeIsAddedToRequest(): void public function notFoundTypeIsAddedToRequest(): void
{ {
$request = ServerRequestFactory::fromGlobals(); $request = ServerRequestFactory::fromGlobals();

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher; namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
@@ -21,7 +22,7 @@ class CloseDbConnectionEventListenerDelegatorTest extends TestCase
$this->delegator = new CloseDbConnectionEventListenerDelegator(); $this->delegator = new CloseDbConnectionEventListenerDelegator();
} }
/** @test */ #[Test]
public function properDependenciesArePassed(): void public function properDependenciesArePassed(): void
{ {
$callbackInvoked = false; $callbackInvoked = false;

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher; namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use RuntimeException; use RuntimeException;
@@ -22,10 +24,7 @@ class CloseDbConnectionEventListenerTest extends TestCase
$this->em = $this->createMock(ReopeningEntityManagerInterface::class); $this->em = $this->createMock(ReopeningEntityManagerInterface::class);
} }
/** #[Test, DataProvider('provideWrapped')]
* @test
* @dataProvider provideWrapped
*/
public function connectionIsOpenedBeforeAndClosedAfter(callable $wrapped, bool &$wrappedWasCalled): void public function connectionIsOpenedBeforeAndClosedAfter(callable $wrapped, bool &$wrappedWasCalled): void
{ {
$conn = $this->createMock(Connection::class); $conn = $this->createMock(Connection::class);

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher; namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\EventDispatcher\Event\GeoLiteDbCreated; use Shlinkio\Shlink\Core\EventDispatcher\Event\GeoLiteDbCreated;
@@ -28,14 +29,14 @@ class LocateUnlocatedVisitsTest extends TestCase
$this->listener = new LocateUnlocatedVisits($this->locator, $this->visitToLocation); $this->listener = new LocateUnlocatedVisits($this->locator, $this->visitToLocation);
} }
/** @test */ #[Test]
public function locatorIsCalledWhenInvoked(): void public function locatorIsCalledWhenInvoked(): void
{ {
$this->locator->expects($this->once())->method('locateUnlocatedVisits')->with($this->listener); $this->locator->expects($this->once())->method('locateUnlocatedVisits')->with($this->listener);
($this->listener)(new GeoLiteDbCreated()); ($this->listener)(new GeoLiteDbCreated());
} }
/** @test */ #[Test]
public function visitToLocationHelperIsCalledToGeolocateVisits(): void public function visitToLocationHelperIsCalledToGeolocateVisits(): void
{ {
$visit = Visit::forBasePath(Visitor::emptyInstance()); $visit = Visit::forBasePath(Visitor::emptyInstance());

View File

@@ -6,6 +6,8 @@ namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use OutOfRangeException; use OutOfRangeException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\EventDispatcherInterface;
@@ -49,7 +51,7 @@ class LocateVisitTest extends TestCase
); );
} }
/** @test */ #[Test]
public function invalidVisitLogsWarning(): void public function invalidVisitLogsWarning(): void
{ {
$event = new UrlVisited('123'); $event = new UrlVisited('123');
@@ -65,7 +67,7 @@ class LocateVisitTest extends TestCase
($this->locateVisit)($event); ($this->locateVisit)($event);
} }
/** @test */ #[Test]
public function nonExistingGeoLiteDbLogsWarning(): void public function nonExistingGeoLiteDbLogsWarning(): void
{ {
$event = new UrlVisited('123'); $event = new UrlVisited('123');
@@ -84,7 +86,7 @@ class LocateVisitTest extends TestCase
($this->locateVisit)($event); ($this->locateVisit)($event);
} }
/** @test */ #[Test]
public function invalidAddressLogsWarning(): void public function invalidAddressLogsWarning(): void
{ {
$event = new UrlVisited('123'); $event = new UrlVisited('123');
@@ -105,7 +107,7 @@ class LocateVisitTest extends TestCase
($this->locateVisit)($event); ($this->locateVisit)($event);
} }
/** @test */ #[Test]
public function unhandledExceptionLogsError(): void public function unhandledExceptionLogsError(): void
{ {
$event = new UrlVisited('123'); $event = new UrlVisited('123');
@@ -126,10 +128,7 @@ class LocateVisitTest extends TestCase
($this->locateVisit)($event); ($this->locateVisit)($event);
} }
/** #[Test, DataProvider('provideNonLocatableVisits')]
* @test
* @dataProvider provideNonLocatableVisits
*/
public function nonLocatableVisitsResolveToEmptyLocations(Visit $visit): void public function nonLocatableVisitsResolveToEmptyLocations(Visit $visit): void
{ {
$event = new UrlVisited('123'); $event = new UrlVisited('123');
@@ -155,10 +154,7 @@ class LocateVisitTest extends TestCase
yield 'localhost' => [Visit::forValidShortUrl($shortUrl, new Visitor('', '', IpAddress::LOCALHOST, ''))]; yield 'localhost' => [Visit::forValidShortUrl($shortUrl, new Visitor('', '', IpAddress::LOCALHOST, ''))];
} }
/** #[Test, DataProvider('provideIpAddresses')]
* @test
* @dataProvider provideIpAddresses
*/
public function locatableVisitsResolveToLocation(Visit $visit, ?string $originalIpAddress): void public function locatableVisitsResolveToLocation(Visit $visit, ?string $originalIpAddress): void
{ {
$ipAddr = $originalIpAddress ?? $visit->getRemoteAddr(); $ipAddr = $originalIpAddress ?? $visit->getRemoteAddr();

View File

@@ -6,6 +6,7 @@ namespace ShlinkioTest\Shlink\Core\EventDispatcher\Mercure;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Exception; use Exception;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@@ -39,7 +40,7 @@ class NotifyNewShortUrlToMercureTest extends TestCase
); );
} }
/** @test */ #[Test]
public function messageIsLoggedWhenShortUrlIsNotFound(): void public function messageIsLoggedWhenShortUrlIsNotFound(): void
{ {
$this->em->expects($this->once())->method('find')->with(ShortUrl::class, '123')->willReturn(null); $this->em->expects($this->once())->method('find')->with(ShortUrl::class, '123')->willReturn(null);
@@ -54,7 +55,7 @@ class NotifyNewShortUrlToMercureTest extends TestCase
($this->listener)(new ShortUrlCreated('123')); ($this->listener)(new ShortUrlCreated('123'));
} }
/** @test */ #[Test]
public function expectedNotificationIsPublished(): void public function expectedNotificationIsPublished(): void
{ {
$shortUrl = ShortUrl::withLongUrl('longUrl'); $shortUrl = ShortUrl::withLongUrl('longUrl');
@@ -71,7 +72,7 @@ class NotifyNewShortUrlToMercureTest extends TestCase
($this->listener)(new ShortUrlCreated('123')); ($this->listener)(new ShortUrlCreated('123'));
} }
/** @test */ #[Test]
public function messageIsPrintedIfPublishingFails(): void public function messageIsPrintedIfPublishingFails(): void
{ {
$shortUrl = ShortUrl::withLongUrl('longUrl'); $shortUrl = ShortUrl::withLongUrl('longUrl');

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher\Mercure; namespace ShlinkioTest\Shlink\Core\EventDispatcher\Mercure;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@@ -37,7 +39,7 @@ class NotifyVisitToMercureTest extends TestCase
$this->listener = new NotifyVisitToMercure($this->helper, $this->updatesGenerator, $this->em, $this->logger); $this->listener = new NotifyVisitToMercure($this->helper, $this->updatesGenerator, $this->em, $this->logger);
} }
/** @test */ #[Test]
public function notificationsAreNotSentWhenVisitCannotBeFound(): void public function notificationsAreNotSentWhenVisitCannotBeFound(): void
{ {
$visitId = '123'; $visitId = '123';
@@ -55,7 +57,7 @@ class NotifyVisitToMercureTest extends TestCase
($this->listener)(new VisitLocated($visitId)); ($this->listener)(new VisitLocated($visitId));
} }
/** @test */ #[Test]
public function notificationsAreSentWhenVisitIsFound(): void public function notificationsAreSentWhenVisitIsFound(): void
{ {
$visitId = '123'; $visitId = '123';
@@ -75,7 +77,7 @@ class NotifyVisitToMercureTest extends TestCase
($this->listener)(new VisitLocated($visitId)); ($this->listener)(new VisitLocated($visitId));
} }
/** @test */ #[Test]
public function debugIsLoggedWhenExceptionIsThrown(): void public function debugIsLoggedWhenExceptionIsThrown(): void
{ {
$visitId = '123'; $visitId = '123';
@@ -99,10 +101,7 @@ class NotifyVisitToMercureTest extends TestCase
($this->listener)(new VisitLocated($visitId)); ($this->listener)(new VisitLocated($visitId));
} }
/** #[Test, DataProvider('provideOrphanVisits')]
* @test
* @dataProvider provideOrphanVisits
*/
public function notificationsAreSentForOrphanVisits(Visit $visit): void public function notificationsAreSentForOrphanVisits(Visit $visit): void
{ {
$visitId = '123'; $visitId = '123';

View File

@@ -12,6 +12,8 @@ use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Promise\RejectedPromise; use GuzzleHttp\Promise\RejectedPromise;
use GuzzleHttp\RequestOptions; use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@@ -41,7 +43,7 @@ class NotifyVisitToWebHooksTest extends TestCase
$this->logger = $this->createMock(LoggerInterface::class); $this->logger = $this->createMock(LoggerInterface::class);
} }
/** @test */ #[Test]
public function emptyWebhooksMakeNoFurtherActions(): void public function emptyWebhooksMakeNoFurtherActions(): void
{ {
$this->em->expects($this->never())->method('find'); $this->em->expects($this->never())->method('find');
@@ -49,7 +51,7 @@ class NotifyVisitToWebHooksTest extends TestCase
$this->createListener([])(new VisitLocated('1')); $this->createListener([])(new VisitLocated('1'));
} }
/** @test */ #[Test]
public function invalidVisitDoesNotPerformAnyRequest(): void public function invalidVisitDoesNotPerformAnyRequest(): void
{ {
$this->em->expects($this->once())->method('find')->with(Visit::class, '1')->willReturn(null); $this->em->expects($this->once())->method('find')->with(Visit::class, '1')->willReturn(null);
@@ -62,7 +64,7 @@ class NotifyVisitToWebHooksTest extends TestCase
$this->createListener(['foo', 'bar'])(new VisitLocated('1')); $this->createListener(['foo', 'bar'])(new VisitLocated('1'));
} }
/** @test */ #[Test]
public function orphanVisitDoesNotPerformAnyRequestWhenDisabled(): void public function orphanVisitDoesNotPerformAnyRequestWhenDisabled(): void
{ {
$this->em->expects($this->once())->method('find')->with(Visit::class, '1')->willReturn( $this->em->expects($this->once())->method('find')->with(Visit::class, '1')->willReturn(
@@ -74,10 +76,7 @@ class NotifyVisitToWebHooksTest extends TestCase
$this->createListener(['foo', 'bar'], false)(new VisitLocated('1')); $this->createListener(['foo', 'bar'], false)(new VisitLocated('1'));
} }
/** #[Test, DataProvider('provideVisits')]
* @test
* @dataProvider provideVisits
*/
public function expectedRequestsArePerformedToWebhooks(Visit $visit, array $expectedResponseKeys): void public function expectedRequestsArePerformedToWebhooks(Visit $visit, array $expectedResponseKeys): void
{ {
$webhooks = ['foo', 'invalid', 'bar', 'baz']; $webhooks = ['foo', 'invalid', 'bar', 'baz'];

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher; namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\UpdatePublishing\Update; use Shlinkio\Shlink\Common\UpdatePublishing\Update;
use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGenerator; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGenerator;
@@ -30,10 +32,7 @@ class PublishingUpdatesGeneratorTest extends TestCase
); );
} }
/** #[Test, DataProvider('provideMethod')]
* @test
* @dataProvider provideMethod
*/
public function visitIsProperlySerializedIntoUpdate(string $method, string $expectedTopic, ?string $title): void public function visitIsProperlySerializedIntoUpdate(string $method, string $expectedTopic, ?string $title): void
{ {
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([ $shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([
@@ -83,10 +82,7 @@ class PublishingUpdatesGeneratorTest extends TestCase
yield 'newShortUrlVisitUpdate' => ['newShortUrlVisitUpdate', 'https://shlink.io/new-visit/foo', null]; yield 'newShortUrlVisitUpdate' => ['newShortUrlVisitUpdate', 'https://shlink.io/new-visit/foo', null];
} }
/** #[Test, DataProvider('provideOrphanVisits')]
* @test
* @dataProvider provideOrphanVisits
*/
public function orphanVisitIsProperlySerializedIntoUpdate(Visit $orphanVisit): void public function orphanVisitIsProperlySerializedIntoUpdate(Visit $orphanVisit): void
{ {
$update = $this->generator->newOrphanVisitUpdate($orphanVisit); $update = $this->generator->newOrphanVisitUpdate($orphanVisit);
@@ -114,7 +110,7 @@ class PublishingUpdatesGeneratorTest extends TestCase
yield VisitType::BASE_URL->value => [Visit::forBasePath($visitor)]; yield VisitType::BASE_URL->value => [Visit::forBasePath($visitor)];
} }
/** @test */ #[Test]
public function shortUrlIsProperlySerializedIntoUpdate(): void public function shortUrlIsProperlySerializedIntoUpdate(): void
{ {
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([ $shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Core\EventDispatcher\RabbitMq;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use DomainException; use DomainException;
use Exception; use Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@@ -36,7 +38,7 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
$this->logger = $this->createMock(LoggerInterface::class); $this->logger = $this->createMock(LoggerInterface::class);
} }
/** @test */ #[Test]
public function doesNothingWhenTheFeatureIsNotEnabled(): void public function doesNothingWhenTheFeatureIsNotEnabled(): void
{ {
$this->helper->expects($this->never())->method('publishUpdate'); $this->helper->expects($this->never())->method('publishUpdate');
@@ -47,7 +49,7 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
($this->listener(false))(new ShortUrlCreated('123')); ($this->listener(false))(new ShortUrlCreated('123'));
} }
/** @test */ #[Test]
public function notificationsAreNotSentWhenShortUrlCannotBeFound(): void public function notificationsAreNotSentWhenShortUrlCannotBeFound(): void
{ {
$shortUrlId = '123'; $shortUrlId = '123';
@@ -62,7 +64,7 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
($this->listener())(new ShortUrlCreated($shortUrlId)); ($this->listener())(new ShortUrlCreated($shortUrlId));
} }
/** @test */ #[Test]
public function expectedChannelIsNotified(): void public function expectedChannelIsNotified(): void
{ {
$shortUrlId = '123'; $shortUrlId = '123';
@@ -79,10 +81,7 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
($this->listener())(new ShortUrlCreated($shortUrlId)); ($this->listener())(new ShortUrlCreated($shortUrlId));
} }
/** #[Test, DataProvider('provideExceptions')]
* @test
* @dataProvider provideExceptions
*/
public function printsDebugMessageInCaseOfError(Throwable $e): void public function printsDebugMessageInCaseOfError(Throwable $e): void
{ {
$shortUrlId = '123'; $shortUrlId = '123';

View File

@@ -8,6 +8,8 @@ use Doctrine\ORM\EntityManagerInterface;
use DomainException; use DomainException;
use Exception; use Exception;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@@ -44,7 +46,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
$this->logger = $this->createMock(LoggerInterface::class); $this->logger = $this->createMock(LoggerInterface::class);
} }
/** @test */ #[Test]
public function doesNothingWhenTheFeatureIsNotEnabled(): void public function doesNothingWhenTheFeatureIsNotEnabled(): void
{ {
$this->helper->expects($this->never())->method('publishUpdate'); $this->helper->expects($this->never())->method('publishUpdate');
@@ -55,7 +57,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
($this->listener(new RabbitMqOptions(enabled: false)))(new VisitLocated('123')); ($this->listener(new RabbitMqOptions(enabled: false)))(new VisitLocated('123'));
} }
/** @test */ #[Test]
public function notificationsAreNotSentWhenVisitCannotBeFound(): void public function notificationsAreNotSentWhenVisitCannotBeFound(): void
{ {
$visitId = '123'; $visitId = '123';
@@ -70,10 +72,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
($this->listener())(new VisitLocated($visitId)); ($this->listener())(new VisitLocated($visitId));
} }
/** #[Test, DataProvider('provideVisits')]
* @test
* @dataProvider provideVisits
*/
public function expectedChannelsAreNotifiedBasedOnTheVisitType(Visit $visit, array $expectedChannels): void public function expectedChannelsAreNotifiedBasedOnTheVisitType(Visit $visit, array $expectedChannels): void
{ {
$visitId = '123'; $visitId = '123';
@@ -108,10 +107,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
]; ];
} }
/** #[Test, DataProvider('provideExceptions')]
* @test
* @dataProvider provideExceptions
*/
public function printsDebugMessageInCaseOfError(Throwable $e): void public function printsDebugMessageInCaseOfError(Throwable $e): void
{ {
$visitId = '123'; $visitId = '123';
@@ -137,10 +133,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
yield [new DomainException('DomainException Error')]; yield [new DomainException('DomainException Error')];
} }
/** #[Test, DataProvider('provideLegacyPayloads')]
* @test
* @dataProvider provideLegacyPayloads
*/
public function expectedPayloadIsPublishedDependingOnConfig( public function expectedPayloadIsPublishedDependingOnConfig(
bool $legacy, bool $legacy,
Visit $visit, Visit $visit,

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Core\EventDispatcher\RedisPubSub;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use DomainException; use DomainException;
use Exception; use Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@@ -35,7 +37,7 @@ class NotifyNewShortUrlToRedisTest extends TestCase
$this->logger = $this->createMock(LoggerInterface::class); $this->logger = $this->createMock(LoggerInterface::class);
} }
/** @test */ #[Test]
public function doesNothingWhenTheFeatureIsNotEnabled(): void public function doesNothingWhenTheFeatureIsNotEnabled(): void
{ {
$this->helper->expects($this->never())->method('publishUpdate'); $this->helper->expects($this->never())->method('publishUpdate');
@@ -46,10 +48,7 @@ class NotifyNewShortUrlToRedisTest extends TestCase
$this->createListener(false)(new ShortUrlCreated('123')); $this->createListener(false)(new ShortUrlCreated('123'));
} }
/** #[Test, DataProvider('provideExceptions')]
* @test
* @dataProvider provideExceptions
*/
public function printsDebugMessageInCaseOfError(Throwable $e): void public function printsDebugMessageInCaseOfError(Throwable $e): void
{ {
$shortUrlId = '123'; $shortUrlId = '123';

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Core\EventDispatcher\RedisPubSub;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use DomainException; use DomainException;
use Exception; use Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@@ -35,7 +37,7 @@ class NotifyVisitToRedisTest extends TestCase
$this->logger = $this->createMock(LoggerInterface::class); $this->logger = $this->createMock(LoggerInterface::class);
} }
/** @test */ #[Test]
public function doesNothingWhenTheFeatureIsNotEnabled(): void public function doesNothingWhenTheFeatureIsNotEnabled(): void
{ {
$this->helper->expects($this->never())->method('publishUpdate'); $this->helper->expects($this->never())->method('publishUpdate');
@@ -46,10 +48,7 @@ class NotifyVisitToRedisTest extends TestCase
$this->createListener(false)(new VisitLocated('123')); $this->createListener(false)(new VisitLocated('123'));
} }
/** #[Test, DataProvider('provideExceptions')]
* @test
* @dataProvider provideExceptions
*/
public function printsDebugMessageInCaseOfError(Throwable $e): void public function printsDebugMessageInCaseOfError(Throwable $e): void
{ {
$visitId = '123'; $visitId = '123';

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher; namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\EventDispatcherInterface;
@@ -32,7 +34,7 @@ class UpdateGeoLiteDbTest extends TestCase
$this->listener = new UpdateGeoLiteDb($this->dbUpdater, $this->logger, $this->eventDispatcher); $this->listener = new UpdateGeoLiteDb($this->dbUpdater, $this->logger, $this->eventDispatcher);
} }
/** @test */ #[Test]
public function exceptionWhileUpdatingDbLogsError(): void public function exceptionWhileUpdatingDbLogsError(): void
{ {
$e = new RuntimeException(); $e = new RuntimeException();
@@ -48,10 +50,7 @@ class UpdateGeoLiteDbTest extends TestCase
($this->listener)(); ($this->listener)();
} }
/** #[Test, DataProvider('provideFlags')]
* @test
* @dataProvider provideFlags
*/
public function noticeMessageIsPrintedWhenFirstCallbackIsInvoked(bool $oldDbExists, string $expectedMessage): void public function noticeMessageIsPrintedWhenFirstCallbackIsInvoked(bool $oldDbExists, string $expectedMessage): void
{ {
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback( $this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback(
@@ -73,10 +72,7 @@ class UpdateGeoLiteDbTest extends TestCase
yield 'not existing old db' => [false, 'Downloading GeoLite2 db file...']; yield 'not existing old db' => [false, 'Downloading GeoLite2 db file...'];
} }
/** #[Test, DataProvider('provideDownloaded')]
* @test
* @dataProvider provideDownloaded
*/
public function noticeMessageIsPrintedWhenSecondCallbackIsInvoked( public function noticeMessageIsPrintedWhenSecondCallbackIsInvoked(
int $total, int $total,
int $downloaded, int $downloaded,
@@ -113,10 +109,7 @@ class UpdateGeoLiteDbTest extends TestCase
yield [100, 101, false, 'Finished downloading GeoLite2 db file']; yield [100, 101, false, 'Finished downloading GeoLite2 db file'];
} }
/** #[Test, DataProvider('provideGeolocationResults')]
* @test
* @dataProvider provideGeolocationResults
*/
public function dispatchesEventOnlyWhenDbFileHasBeenCreatedForTheFirstTime( public function dispatchesEventOnlyWhenDbFileHasBeenCreatedForTheFirstTime(
GeolocationResult $result, GeolocationResult $result,
int $expectedDispatches, int $expectedDispatches,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Functions; namespace ShlinkioTest\Shlink\Core\Functions;
use BackedEnum; use BackedEnum;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\EnvVars; use Shlinkio\Shlink\Core\Config\EnvVars;
use Shlinkio\Shlink\Core\Model\DeviceType; use Shlinkio\Shlink\Core\Model\DeviceType;
@@ -18,9 +20,8 @@ class FunctionsTest extends TestCase
{ {
/** /**
* @param class-string<BackedEnum> $enum * @param class-string<BackedEnum> $enum
* @test
* @dataProvider provideEnums
*/ */
#[Test, DataProvider('provideEnums')]
public function enumValuesReturnsExpectedValueForEnum(string $enum, array $expectedValues): void public function enumValuesReturnsExpectedValueForEnum(string $enum, array $expectedValues): void
{ {
self::assertEquals($expectedValues, enumValues($enum)); self::assertEquals($expectedValues, enumValues($enum));

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Core\Importer;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use RuntimeException; use RuntimeException;
@@ -61,7 +63,7 @@ class ImportedLinksProcessorTest extends TestCase
$this->io = $this->createMock(StyleInterface::class); $this->io = $this->createMock(StyleInterface::class);
} }
/** @test */ #[Test]
public function newUrlsWithNoErrorsAreAllPersisted(): void public function newUrlsWithNoErrorsAreAllPersisted(): void
{ {
$urls = [ $urls = [
@@ -84,7 +86,7 @@ class ImportedLinksProcessorTest extends TestCase
$this->processor->process($this->io, ImportResult::withShortUrls($urls), $this->buildParams()); $this->processor->process($this->io, ImportResult::withShortUrls($urls), $this->buildParams());
} }
/** @test */ #[Test]
public function newUrlsWithErrorsAreSkipped(): void public function newUrlsWithErrorsAreSkipped(): void
{ {
$urls = [ $urls = [
@@ -111,7 +113,7 @@ class ImportedLinksProcessorTest extends TestCase
self::assertEquals(1, $textCalls->skippedCount); self::assertEquals(1, $textCalls->skippedCount);
} }
/** @test */ #[Test]
public function alreadyImportedUrlsAreSkipped(): void public function alreadyImportedUrlsAreSkipped(): void
{ {
$urls = [ $urls = [
@@ -137,7 +139,7 @@ class ImportedLinksProcessorTest extends TestCase
self::assertEquals(3, $textCalls->skippedCount); self::assertEquals(3, $textCalls->skippedCount);
} }
/** @test */ #[Test]
public function nonUniqueShortCodesAreAskedToUser(): void public function nonUniqueShortCodesAreAskedToUser(): void
{ {
$urls = [ $urls = [
@@ -165,10 +167,7 @@ class ImportedLinksProcessorTest extends TestCase
self::assertEquals(3, $textCalls->skippedCount); self::assertEquals(3, $textCalls->skippedCount);
} }
/** #[Test, DataProvider('provideUrlsWithVisits')]
* @test
* @dataProvider provideUrlsWithVisits
*/
public function properAmountOfVisitsIsImported( public function properAmountOfVisitsIsImported(
ImportedShlinkUrl $importedUrl, ImportedShlinkUrl $importedUrl,
string $expectedOutput, string $expectedOutput,
@@ -230,9 +229,8 @@ class ImportedLinksProcessorTest extends TestCase
/** /**
* @param iterable<ImportedShlinkOrphanVisit> $visits * @param iterable<ImportedShlinkOrphanVisit> $visits
* @test
* @dataProvider provideOrphanVisits
*/ */
#[Test, DataProvider('provideOrphanVisits')]
public function properAmountOfOrphanVisitsIsImported( public function properAmountOfOrphanVisitsIsImported(
bool $importOrphanVisits, bool $importOrphanVisits,
iterable $visits, iterable $visits,

View File

@@ -6,6 +6,7 @@ namespace ShlinkioTest\Shlink\Core\ShortUrl;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException; use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
@@ -40,7 +41,7 @@ class DeleteShortUrlServiceTest extends TestCase
$this->urlResolver->method('resolveShortUrl')->willReturn($shortUrl); $this->urlResolver->method('resolveShortUrl')->willReturn($shortUrl);
} }
/** @test */ #[Test]
public function deleteByShortCodeThrowsExceptionWhenThresholdIsReached(): void public function deleteByShortCodeThrowsExceptionWhenThresholdIsReached(): void
{ {
$service = $this->createService(); $service = $this->createService();
@@ -54,7 +55,7 @@ class DeleteShortUrlServiceTest extends TestCase
$service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode)); $service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode));
} }
/** @test */ #[Test]
public function deleteByShortCodeDeletesUrlWhenThresholdIsReachedButExplicitlyIgnored(): void public function deleteByShortCodeDeletesUrlWhenThresholdIsReachedButExplicitlyIgnored(): void
{ {
$service = $this->createService(); $service = $this->createService();
@@ -67,7 +68,7 @@ class DeleteShortUrlServiceTest extends TestCase
$service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode), true); $service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode), true);
} }
/** @test */ #[Test]
public function deleteByShortCodeDeletesUrlWhenThresholdIsReachedButCheckIsDisabled(): void public function deleteByShortCodeDeletesUrlWhenThresholdIsReachedButCheckIsDisabled(): void
{ {
$service = $this->createService(false); $service = $this->createService(false);
@@ -80,7 +81,7 @@ class DeleteShortUrlServiceTest extends TestCase
$service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode)); $service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode));
} }
/** @test */ #[Test]
public function deleteByShortCodeDeletesUrlWhenThresholdIsNotReached(): void public function deleteByShortCodeDeletesUrlWhenThresholdIsNotReached(): void
{ {
$service = $this->createService(true, 100); $service = $this->createService(true, 100);

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Entity; namespace ShlinkioTest\Shlink\Core\ShortUrl\Entity;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\ShortCodeCannotBeRegeneratedException; use Shlinkio\Shlink\Core\Exception\ShortCodeCannotBeRegeneratedException;
use Shlinkio\Shlink\Core\Model\DeviceType; use Shlinkio\Shlink\Core\Model\DeviceType;
@@ -27,10 +29,7 @@ use const Shlinkio\Shlink\DEFAULT_SHORT_CODES_LENGTH;
class ShortUrlTest extends TestCase class ShortUrlTest extends TestCase
{ {
/** #[Test, DataProvider('provideInvalidShortUrls')]
* @test
* @dataProvider provideInvalidShortUrls
*/
public function regenerateShortCodeThrowsExceptionIfStateIsInvalid( public function regenerateShortCodeThrowsExceptionIfStateIsInvalid(
ShortUrl $shortUrl, ShortUrl $shortUrl,
string $expectedMessage, string $expectedMessage,
@@ -53,10 +52,7 @@ class ShortUrlTest extends TestCase
]; ];
} }
/** #[Test, DataProvider('provideValidShortUrls')]
* @test
* @dataProvider provideValidShortUrls
*/
public function regenerateShortCodeProperlyChangesTheValueOnValidShortUrls( public function regenerateShortCodeProperlyChangesTheValueOnValidShortUrls(
ShortUrl $shortUrl, ShortUrl $shortUrl,
): void { ): void {
@@ -77,10 +73,7 @@ class ShortUrlTest extends TestCase
)]; )];
} }
/** #[Test, DataProvider('provideLengths')]
* @test
* @dataProvider provideLengths
*/
public function shortCodesHaveExpectedLength(?int $length, int $expectedLength): void public function shortCodesHaveExpectedLength(?int $length, int $expectedLength): void
{ {
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData( $shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(
@@ -96,7 +89,7 @@ class ShortUrlTest extends TestCase
yield from map(range(4, 10), fn (int $value) => [$value, $value]); yield from map(range(4, 10), fn (int $value) => [$value, $value]);
} }
/** @test */ #[Test]
public function deviceLongUrlsAreUpdated(): void public function deviceLongUrlsAreUpdated(): void
{ {
$shortUrl = ShortUrl::withLongUrl('foo'); $shortUrl = ShortUrl::withLongUrl('foo');
@@ -138,7 +131,7 @@ class ShortUrlTest extends TestCase
], $shortUrl->deviceLongUrls()); ], $shortUrl->deviceLongUrls());
} }
/** @test */ #[Test]
public function generatesLowercaseOnlyShortCodesInLooseMode(): void public function generatesLowercaseOnlyShortCodesInLooseMode(): void
{ {
$range = range(1, 1000); // Use a "big" number to reduce false negatives $range = range(1, 1000); // Use a "big" number to reduce false negatives

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper; namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Entity\Domain;
@@ -29,10 +31,7 @@ class ShortCodeUniquenessHelperTest extends TestCase
$this->shortUrl->method('getShortCode')->willReturn('abc123'); $this->shortUrl->method('getShortCode')->willReturn('abc123');
} }
/** #[Test, DataProvider('provideDomains')]
* @test
* @dataProvider provideDomains
*/
public function shortCodeIsRegeneratedIfAlreadyInUse(?Domain $domain, ?string $expectedAuthority): void public function shortCodeIsRegeneratedIfAlreadyInUse(?Domain $domain, ?string $expectedAuthority): void
{ {
$callIndex = 0; $callIndex = 0;
@@ -61,7 +60,7 @@ class ShortCodeUniquenessHelperTest extends TestCase
yield 'domain' => [Domain::withAuthority($authority = 's.test'), $authority]; yield 'domain' => [Domain::withAuthority($authority = 's.test'), $authority];
} }
/** @test */ #[Test]
public function inUseSlugReturnsError(): void public function inUseSlugReturnsError(): void
{ {
$repo = $this->createMock(ShortUrlRepository::class); $repo = $this->createMock(ShortUrlRepository::class);

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper; namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Core\Model\DeviceType; use Shlinkio\Shlink\Core\Model\DeviceType;
@@ -27,10 +29,7 @@ class ShortUrlRedirectionBuilderTest extends TestCase
$this->redirectionBuilder = new ShortUrlRedirectionBuilder($trackingOptions); $this->redirectionBuilder = new ShortUrlRedirectionBuilder($trackingOptions);
} }
/** #[Test, DataProvider('provideData')]
* @test
* @dataProvider provideData
*/
public function buildShortUrlRedirectBuildsExpectedUrl( public function buildShortUrlRedirectBuildsExpectedUrl(
string $expectedUrl, string $expectedUrl,
ServerRequestInterface $request, ServerRequestInterface $request,

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper; namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
@@ -11,10 +13,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
class ShortUrlStringifierTest extends TestCase class ShortUrlStringifierTest extends TestCase
{ {
/** #[Test, DataProvider('provideConfigAndShortUrls')]
* @test
* @dataProvider provideConfigAndShortUrls
*/
public function generatesExpectedOutputBasedOnConfigAndShortUrl( public function generatesExpectedOutputBasedOnConfigAndShortUrl(
array $config, array $config,
string $basePath, string $basePath,

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper; namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlTitleResolutionHelper; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlTitleResolutionHelper;
@@ -21,10 +23,7 @@ class ShortUrlTitleResolutionHelperTest extends TestCase
$this->helper = new ShortUrlTitleResolutionHelper($this->urlValidator); $this->helper = new ShortUrlTitleResolutionHelper($this->urlValidator);
} }
/** #[Test, DataProvider('provideTitles')]
* @test
* @dataProvider provideTitles
*/
public function urlIsProperlyShortened(?string $title, int $validateWithTitleCallsNum, int $validateCallsNum): void public function urlIsProperlyShortened(?string $title, int $validateWithTitleCallsNum, int $validateCallsNum): void
{ {
$longUrl = 'http://foobar.com/12345/hello?foo=bar'; $longUrl = 'http://foobar.com/12345/hello?foo=bar';

View File

@@ -9,6 +9,8 @@ use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\Uri; use Laminas\Diactoros\Uri;
use Mezzio\Router\Route; use Mezzio\Router\Route;
use Mezzio\Router\RouteResult; use Mezzio\Router\RouteResult;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@@ -46,10 +48,7 @@ class ExtraPathRedirectMiddlewareTest extends TestCase
$this->handler->method('handle')->willReturn(new RedirectResponse('')); $this->handler->method('handle')->willReturn(new RedirectResponse(''));
} }
/** #[Test, DataProvider('provideNonRedirectingRequests')]
* @test
* @dataProvider provideNonRedirectingRequests
*/
public function handlerIsCalledWhenConfigPreventsRedirectWithExtraPath( public function handlerIsCalledWhenConfigPreventsRedirectWithExtraPath(
bool $appendExtraPath, bool $appendExtraPath,
bool $multiSegmentEnabled, bool $multiSegmentEnabled,
@@ -101,10 +100,7 @@ class ExtraPathRedirectMiddlewareTest extends TestCase
]; ];
} }
/** #[Test, DataProvider('provideResolves')]
* @test
* @dataProvider provideResolves
*/
public function handlerIsCalledWhenNoShortUrlIsFoundAfterExpectedAmountOfIterations( public function handlerIsCalledWhenNoShortUrlIsFoundAfterExpectedAmountOfIterations(
bool $multiSegmentEnabled, bool $multiSegmentEnabled,
int $expectedResolveCalls, int $expectedResolveCalls,
@@ -127,10 +123,7 @@ class ExtraPathRedirectMiddlewareTest extends TestCase
$this->middleware($options)->process($request, $this->handler); $this->middleware($options)->process($request, $this->handler);
} }
/** #[Test, DataProvider('provideResolves')]
* @test
* @dataProvider provideResolves
*/
public function visitIsTrackedAndRedirectIsReturnedWhenShortUrlIsFoundAfterExpectedAmountOfIterations( public function visitIsTrackedAndRedirectIsReturnedWhenShortUrlIsFoundAfterExpectedAmountOfIterations(
bool $multiSegmentEnabled, bool $multiSegmentEnabled,
int $expectedResolveCalls, int $expectedResolveCalls,

View File

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Core\ShortUrl\Middleware;
use Laminas\Diactoros\Response; use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@@ -26,10 +28,7 @@ class TrimTrailingSlashMiddlewareTest extends TestCase
$this->requestHandler = $this->createMock(RequestHandlerInterface::class); $this->requestHandler = $this->createMock(RequestHandlerInterface::class);
} }
/** #[Test, DataProvider('provideRequests')]
* @test
* @dataProvider provideRequests
*/
public function returnsExpectedResponse( public function returnsExpectedResponse(
bool $trailingSlashEnabled, bool $trailingSlashEnabled,
ServerRequestInterface $inputRequest, ServerRequestInterface $inputRequest,

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Model; namespace ShlinkioTest\Shlink\Core\ShortUrl\Model;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\Exception\ValidationException;
use Shlinkio\Shlink\Core\Model\DeviceType; use Shlinkio\Shlink\Core\Model\DeviceType;
@@ -20,11 +22,7 @@ use const STR_PAD_BOTH;
class ShortUrlCreationTest extends TestCase class ShortUrlCreationTest extends TestCase
{ {
/** #[Test, DataProvider('provideInvalidData')]
* @param array $data
* @test
* @dataProvider provideInvalidData
*/
public function exceptionIsThrownIfProvidedDataIsInvalid(array $data): void public function exceptionIsThrownIfProvidedDataIsInvalid(array $data): void
{ {
$this->expectException(ValidationException::class); $this->expectException(ValidationException::class);
@@ -107,10 +105,7 @@ class ShortUrlCreationTest extends TestCase
]]; ]];
} }
/** #[Test, DataProvider('provideCustomSlugs')]
* @test
* @dataProvider provideCustomSlugs
*/
public function properlyCreatedInstanceReturnsValues( public function properlyCreatedInstanceReturnsValues(
string $customSlug, string $customSlug,
string $expectedSlug, string $expectedSlug,
@@ -161,10 +156,7 @@ class ShortUrlCreationTest extends TestCase
yield ['гугл', 'гугл']; yield ['гугл', 'гугл'];
} }
/** #[Test, DataProvider('provideTitles')]
* @test
* @dataProvider provideTitles
*/
public function titleIsCroppedIfTooLong(?string $title, ?string $expectedTitle): void public function titleIsCroppedIfTooLong(?string $title, ?string $expectedTitle): void
{ {
$creation = ShortUrlCreation::fromRawData([ $creation = ShortUrlCreation::fromRawData([
@@ -187,10 +179,7 @@ class ShortUrlCreationTest extends TestCase
yield [str_pad('', 800, 'e'), str_pad('', 512, 'e')]; yield [str_pad('', 800, 'e'), str_pad('', 512, 'e')];
} }
/** #[Test, DataProvider('provideDomains')]
* @test
* @dataProvider provideDomains
*/
public function emptyDomainIsDiscarded(?string $domain, ?string $expectedDomain): void public function emptyDomainIsDiscarded(?string $domain, ?string $expectedDomain): void
{ {
$creation = ShortUrlCreation::fromRawData([ $creation = ShortUrlCreation::fromRawData([

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Model; namespace ShlinkioTest\Shlink\Core\ShortUrl\Model;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Model\DeviceType; use Shlinkio\Shlink\Core\Model\DeviceType;
use Shlinkio\Shlink\Core\ShortUrl\Model\DeviceLongUrlPair; use Shlinkio\Shlink\Core\ShortUrl\Model\DeviceLongUrlPair;
@@ -12,10 +14,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
class ShortUrlEditionTest extends TestCase class ShortUrlEditionTest extends TestCase
{ {
/** #[Test, DataProvider('provideDeviceLongUrls')]
* @test
* @dataProvider provideDeviceLongUrls
*/
public function expectedDeviceLongUrlsAreResolved( public function expectedDeviceLongUrlsAreResolved(
?array $deviceLongUrls, ?array $deviceLongUrls,
array $expectedDeviceLongUrls, array $expectedDeviceLongUrls,

View File

@@ -4,15 +4,14 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Model; namespace ShlinkioTest\Shlink\Core\ShortUrl\Model;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode;
class ShortUrlModeTest extends TestCase class ShortUrlModeTest extends TestCase
{ {
/** #[Test, DataProvider('provideModes')]
* @test
* @dataProvider provideModes
*/
public function deprecatedValuesAreProperlyParsed(string $mode, ?ShortUrlMode $expected): void public function deprecatedValuesAreProperlyParsed(string $mode, ?ShortUrlMode $expected): void
{ {
self::assertSame($expected, ShortUrlMode::tryDeprecated($mode)); self::assertSame($expected, ShortUrlMode::tryDeprecated($mode));

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Model\Validation; namespace ShlinkioTest\Shlink\Core\ShortUrl\Model\Validation;
use Laminas\Validator\NotEmpty; use Laminas\Validator\NotEmpty;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Model\DeviceType; use Shlinkio\Shlink\Core\Model\DeviceType;
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\DeviceLongUrlsValidator; use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\DeviceLongUrlsValidator;
@@ -19,10 +21,7 @@ class DeviceLongUrlsValidatorTest extends TestCase
$this->validator = new DeviceLongUrlsValidator(new NotEmpty()); $this->validator = new DeviceLongUrlsValidator(new NotEmpty());
} }
/** #[Test, DataProvider('provideNonArrayValues')]
* @test
* @dataProvider provideNonArrayValues
*/
public function nonArrayValuesAreNotValid(mixed $invalidValue): void public function nonArrayValuesAreNotValid(mixed $invalidValue): void
{ {
self::assertFalse($this->validator->isValid($invalidValue)); self::assertFalse($this->validator->isValid($invalidValue));
@@ -39,7 +38,7 @@ class DeviceLongUrlsValidatorTest extends TestCase
yield 'null' => [null]; yield 'null' => [null];
} }
/** @test */ #[Test]
public function unrecognizedKeysAreNotValid(): void public function unrecognizedKeysAreNotValid(): void
{ {
self::assertFalse($this->validator->isValid(['foo' => 'bar'])); self::assertFalse($this->validator->isValid(['foo' => 'bar']));
@@ -49,7 +48,7 @@ class DeviceLongUrlsValidatorTest extends TestCase
); );
} }
/** @test */ #[Test]
public function everyUrlMustMatchLongUrlValidator(): void public function everyUrlMustMatchLongUrlValidator(): void
{ {
self::assertFalse($this->validator->isValid([DeviceType::ANDROID->value => ''])); self::assertFalse($this->validator->isValid([DeviceType::ANDROID->value => '']));
@@ -59,7 +58,7 @@ class DeviceLongUrlsValidatorTest extends TestCase
); );
} }
/** @test */ #[Test]
public function validValuesResultInValidResult(): void public function validValuesResultInValidResult(): void
{ {
self::assertTrue($this->validator->isValid([ self::assertTrue($this->validator->isValid([

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Paginator\Adapter; namespace ShlinkioTest\Shlink\Core\ShortUrl\Paginator\Adapter;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
@@ -24,10 +26,7 @@ class ShortUrlRepositoryAdapterTest extends TestCase
$this->repo = $this->createMock(ShortUrlListRepositoryInterface::class); $this->repo = $this->createMock(ShortUrlListRepositoryInterface::class);
} }
/** #[Test, DataProvider('provideFilteringArgs')]
* @test
* @dataProvider provideFilteringArgs
*/
public function getItemsFallsBackToFindList( public function getItemsFallsBackToFindList(
?string $searchTerm = null, ?string $searchTerm = null,
array $tags = [], array $tags = [],
@@ -53,10 +52,7 @@ class ShortUrlRepositoryAdapterTest extends TestCase
$adapter->getSlice(5, 10); $adapter->getSlice(5, 10);
} }
/** #[Test, DataProvider('provideFilteringArgs')]
* @test
* @dataProvider provideFilteringArgs
*/
public function countFallsBackToCountList( public function countFallsBackToCountList(
?string $searchTerm = null, ?string $searchTerm = null,
array $tags = [], array $tags = [],

View File

@@ -6,6 +6,8 @@ namespace ShlinkioTest\Shlink\Core\ShortUrl\Resolver;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Entity\Domain;
@@ -29,17 +31,14 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
$this->resolver = new PersistenceShortUrlRelationResolver($this->em); $this->resolver = new PersistenceShortUrlRelationResolver($this->em);
} }
/** @test */ #[Test]
public function returnsEmptyWhenNoDomainIsProvided(): void public function returnsEmptyWhenNoDomainIsProvided(): void
{ {
$this->em->expects($this->never())->method('getRepository')->with(Domain::class); $this->em->expects($this->never())->method('getRepository')->with(Domain::class);
self::assertNull($this->resolver->resolveDomain(null)); self::assertNull($this->resolver->resolveDomain(null));
} }
/** #[Test, DataProvider('provideFoundDomains')]
* @test
* @dataProvider provideFoundDomains
*/
public function findsOrCreatesDomainWhenValueIsProvided(?Domain $foundDomain, string $authority): void public function findsOrCreatesDomainWhenValueIsProvided(?Domain $foundDomain, string $authority): void
{ {
$repo = $this->createMock(DomainRepositoryInterface::class); $repo = $this->createMock(DomainRepositoryInterface::class);
@@ -63,10 +62,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
yield 'found domain' => [Domain::withAuthority($authority), $authority]; yield 'found domain' => [Domain::withAuthority($authority), $authority];
} }
/** #[Test, DataProvider('provideTags')]
* @test
* @dataProvider provideTags
*/
public function findsAndPersistsTagsWrappedIntoCollection(array $tags, array $expectedTags): void public function findsAndPersistsTagsWrappedIntoCollection(array $tags, array $expectedTags): void
{ {
$expectedPersistedTags = count($expectedTags); $expectedPersistedTags = count($expectedTags);
@@ -95,7 +91,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
yield 'duplicated tags' => [['foo', 'bar', 'bar'], [new Tag('foo'), new Tag('bar')]]; yield 'duplicated tags' => [['foo', 'bar', 'bar'], [new Tag('foo'), new Tag('bar')]];
} }
/** @test */ #[Test]
public function returnsEmptyCollectionWhenProvidingEmptyListOfTags(): void public function returnsEmptyCollectionWhenProvidingEmptyListOfTags(): void
{ {
$this->em->expects($this->never())->method('getRepository')->with(Tag::class); $this->em->expects($this->never())->method('getRepository')->with(Tag::class);
@@ -106,7 +102,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
self::assertEmpty($result); self::assertEmpty($result);
} }
/** @test */ #[Test]
public function newDomainsAreMemoizedUntilStateIsCleared(): void public function newDomainsAreMemoizedUntilStateIsCleared(): void
{ {
$repo = $this->createMock(DomainRepositoryInterface::class); $repo = $this->createMock(DomainRepositoryInterface::class);
@@ -125,7 +121,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
self::assertNotSame($domain1, $domain3); self::assertNotSame($domain1, $domain3);
} }
/** @test */ #[Test]
public function newTagsAreMemoizedUntilStateIsCleared(): void public function newTagsAreMemoizedUntilStateIsCleared(): void
{ {
$tagRepo = $this->createMock(TagRepositoryInterface::class); $tagRepo = $this->createMock(TagRepositoryInterface::class);

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl\Resolver; namespace ShlinkioTest\Shlink\Core\ShortUrl\Resolver;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Entity\Domain;
use Shlinkio\Shlink\Core\ShortUrl\Resolver\SimpleShortUrlRelationResolver; use Shlinkio\Shlink\Core\ShortUrl\Resolver\SimpleShortUrlRelationResolver;
@@ -18,10 +20,7 @@ class SimpleShortUrlRelationResolverTest extends TestCase
$this->resolver = new SimpleShortUrlRelationResolver(); $this->resolver = new SimpleShortUrlRelationResolver();
} }
/** #[Test, DataProvider('provideDomains')]
* @test
* @dataProvider provideDomains
*/
public function resolvesExpectedDomain(?string $domain): void public function resolvesExpectedDomain(?string $domain): void
{ {
$result = $this->resolver->resolveDomain($domain); $result = $this->resolver->resolveDomain($domain);
@@ -40,7 +39,7 @@ class SimpleShortUrlRelationResolverTest extends TestCase
yield 'non-empty domain' => ['domain.com']; yield 'non-empty domain' => ['domain.com'];
} }
/** @test */ #[Test]
public function tagsAreWrappedInEntityCollection(): void public function tagsAreWrappedInEntityCollection(): void
{ {
$tags = ['foo', 'bar', 'baz']; $tags = ['foo', 'bar', 'baz'];

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ShortUrl; namespace ShlinkioTest\Shlink\Core\ShortUrl;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Options\UrlShortenerOptions;
@@ -29,10 +31,7 @@ class ShortUrlListServiceTest extends TestCase
$this->service = new ShortUrlListService($this->repo, new UrlShortenerOptions()); $this->service = new ShortUrlListService($this->repo, new UrlShortenerOptions());
} }
/** #[Test, DataProvider('provideAdminApiKeys')]
* @test
* @dataProvider provideAdminApiKeys
*/
public function listedUrlsAreReturnedFromEntityManager(?ApiKey $apiKey): void public function listedUrlsAreReturnedFromEntityManager(?ApiKey $apiKey): void
{ {
$list = [ $list = [

Some files were not shown because too many files have changed in this diff Show More