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

@@ -7,6 +7,8 @@ namespace ShlinkioTest\Shlink\Rest\Service;
use Cake\Chronos\Chronos;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
@@ -30,10 +32,9 @@ class ApiKeyServiceTest extends TestCase
}
/**
* @test
* @dataProvider provideCreationDate
* @param RoleDefinition[] $roles
*/
#[Test, DataProvider('provideCreationDate')]
public function apiKeyIsProperlyCreated(?Chronos $date, ?string $name, array $roles): void
{
$this->em->expects($this->once())->method('flush');
@@ -64,10 +65,7 @@ class ApiKeyServiceTest extends TestCase
yield 'empty name' => [null, '', []];
}
/**
* @test
* @dataProvider provideInvalidApiKeys
*/
#[Test, DataProvider('provideInvalidApiKeys')]
public function checkReturnsFalseForInvalidApiKeys(?ApiKey $invalidKey): void
{
$this->repo->expects($this->once())->method('findOneBy')->with(['key' => '12345'])->willReturn($invalidKey);
@@ -86,7 +84,7 @@ class ApiKeyServiceTest extends TestCase
yield 'expired api key' => [ApiKey::fromMeta(ApiKeyMeta::withExpirationDate(Chronos::now()->subDay()))];
}
/** @test */
#[Test]
public function checkReturnsTrueWhenConditionsAreFavorable(): void
{
$apiKey = ApiKey::create();
@@ -100,7 +98,7 @@ class ApiKeyServiceTest extends TestCase
self::assertSame($apiKey, $result->apiKey);
}
/** @test */
#[Test]
public function disableThrowsExceptionWhenNoApiKeyIsFound(): void
{
$this->repo->expects($this->once())->method('findOneBy')->with(['key' => '12345'])->willReturn(null);
@@ -111,7 +109,7 @@ class ApiKeyServiceTest extends TestCase
$this->service->disable('12345');
}
/** @test */
#[Test]
public function disableReturnsDisabledApiKeyWhenFound(): void
{
$key = ApiKey::create();
@@ -125,7 +123,7 @@ class ApiKeyServiceTest extends TestCase
self::assertSame($key, $returnedKey);
}
/** @test */
#[Test]
public function listFindsAllApiKeys(): void
{
$expectedApiKeys = [ApiKey::create(), ApiKey::create(), ApiKey::create()];
@@ -138,7 +136,7 @@ class ApiKeyServiceTest extends TestCase
self::assertEquals($expectedApiKeys, $result);
}
/** @test */
#[Test]
public function listEnabledFindsOnlyEnabledApiKeys(): void
{
$expectedApiKeys = [ApiKey::create(), ApiKey::create(), ApiKey::create()];