Converted Role constants to enum

This commit is contained in:
Alejandro Celaya
2022-04-23 18:41:16 +02:00
parent 404455928e
commit e8f7daac6f
14 changed files with 66 additions and 59 deletions

View File

@@ -16,7 +16,7 @@ class RoleDefinitionTest extends TestCase
{
$definition = RoleDefinition::forAuthoredShortUrls();
self::assertEquals(Role::AUTHORED_SHORT_URLS, $definition->roleName);
self::assertEquals(Role::AUTHORED_SHORT_URLS, $definition->role);
self::assertEquals([], $definition->meta);
}
@@ -26,7 +26,7 @@ class RoleDefinitionTest extends TestCase
$domain = Domain::withAuthority('foo.com')->setId('123');
$definition = RoleDefinition::forDomain($domain);
self::assertEquals(Role::DOMAIN_SPECIFIC, $definition->roleName);
self::assertEquals(Role::DOMAIN_SPECIFIC, $definition->role);
self::assertEquals(['domain_id' => '123', 'authority' => 'foo.com'], $definition->meta);
}
}

View File

@@ -30,7 +30,6 @@ class RoleTest extends TestCase
{
$apiKey = ApiKey::create();
yield 'invalid role' => [new ApiKeyRole('invalid', [], $apiKey), Spec::andX()];
yield 'author role' => [
new ApiKeyRole(Role::AUTHORED_SHORT_URLS, [], $apiKey),
new BelongsToApiKey($apiKey),
@@ -54,7 +53,6 @@ class RoleTest extends TestCase
{
$apiKey = ApiKey::create();
yield 'invalid role' => [new ApiKeyRole('invalid', [], $apiKey), Spec::andX()];
yield 'author role' => [
new ApiKeyRole(Role::AUTHORED_SHORT_URLS, [], $apiKey),
Spec::andX(new BelongsToApiKeyInlined($apiKey)),
@@ -101,15 +99,14 @@ class RoleTest extends TestCase
* @test
* @dataProvider provideRoleNames
*/
public function getsExpectedRoleFriendlyName(string $roleName, string $expectedFriendlyName): void
public function getsExpectedRoleFriendlyName(Role $roleName, string $expectedFriendlyName): void
{
self::assertEquals($expectedFriendlyName, Role::toFriendlyName($roleName));
}
public function provideRoleNames(): iterable
{
yield 'unknown' => ['unknown', ''];
yield Role::AUTHORED_SHORT_URLS => [Role::AUTHORED_SHORT_URLS, 'Author only'];
yield Role::DOMAIN_SPECIFIC => [Role::DOMAIN_SPECIFIC, 'Domain only'];
yield Role::AUTHORED_SHORT_URLS->value => [Role::AUTHORED_SHORT_URLS, 'Author only'];
yield Role::DOMAIN_SPECIFIC->value => [Role::DOMAIN_SPECIFIC, 'Domain only'];
}
}