*/ public static function expectations(): array { return [ 'superuser' => [Role::Superuser, 'superuser', 'Superuser', 'NIP', Superuser::class], 'admin' => [Role::Admin, 'admin', 'Admin', 'NIP', Admin::class], 'operator' => [Role::Operator, 'operator', 'Operator', 'NIP', Operator::class], 'dosen' => [Role::Dosen, 'dosen', 'Dosen', 'NIDN', Dosen::class], 'mahasiswa' => [Role::Mahasiswa, 'mahasiswa', 'Mahasiswa', 'NIM', Mahasiswa::class], ]; } public function test_there_are_exactly_five_roles_in_the_documented_order(): void { $this->assertSame( ['superuser', 'admin', 'operator', 'dosen', 'mahasiswa'], array_map(fn (Role $role): string => $role->value, Role::cases()), ); $this->assertSame(['superuser', 'admin', 'operator', 'dosen', 'mahasiswa'], Role::values()); } /** @param class-string $model */ #[DataProvider('expectations')] public function test_role_metadata(Role $role, string $value, string $label, string $identifier, string $model): void { $this->assertSame($value, $role->value); $this->assertSame($label, $role->label()); $this->assertSame("{$value}.dashboard", $role->dashboardRoute()); $this->assertSame($value, $role->routePrefix()); $this->assertSame($value, $role->profileRelation()); $this->assertSame($model, $role->profileModel()); $this->assertSame($identifier, $role->identifierLabel()); } #[DataProvider('expectations')] public function test_role_can_be_resolved_from_its_value(Role $role, string $value): void { $this->assertSame($role, Role::from($value)); $this->assertSame($role, Role::tryFrom($value)); } public function test_unknown_values_do_not_resolve(): void { $this->assertNull(Role::tryFrom('rektor')); $this->assertNull(Role::tryFrom('Admin')); } public function test_options_map_values_to_labels(): void { $this->assertSame([ 'superuser' => 'Superuser', 'admin' => 'Admin', 'operator' => 'Operator', 'dosen' => 'Dosen', 'mahasiswa' => 'Mahasiswa', ], Role::options()); } public function test_profile_relation_is_a_has_one_on_user_for_every_role(): void { foreach (Role::cases() as $role) { $this->assertTrue(method_exists(User::class, $role->profileRelation()), "User::{$role->profileRelation()}() belum ada."); $relation = (new User)->{$role->profileRelation()}(); $this->assertInstanceOf(HasOne::class, $relation); $this->assertInstanceOf($role->profileModel(), $relation->getRelated()); } } public function test_every_profile_model_has_its_own_namespace_folder(): void { foreach (Role::cases() as $role) { $this->assertSame("App\\Models\\{$role->label()}\\{$role->label()}", $role->profileModel()); } } public function test_identifier_labels_are_nip_nidn_nim_only(): void { $labels = array_values(array_unique(array_map(fn (Role $role): string => $role->identifierLabel(), Role::cases()))); $this->assertEqualsCanonicalizing(['NIP', 'NIDN', 'NIM'], $labels); } }