File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 44
55namespace Tests \Feature ;
66
7+ use Contexts \Authorization \Domain \Role \Models \RoleStatus ;
78use Contexts \Authorization \Domain \UserIdentity \Models \UserStatus ;
9+ use Contexts \Authorization \Infrastructure \Records \RoleRecord ;
810use Contexts \Authorization \Infrastructure \Records \UserRecord ;
911
1012trait AuthenticationSupport
@@ -21,4 +23,23 @@ protected function loginAsUser(array $attributes = []): void
2123
2224 $ this ->actingAs ($ userRecord );
2325 }
26+
27+ protected function loginAsAdmin (array $ attributes = []): void
28+ {
29+ $ userRecord = UserRecord::factory ()->create ([
30+ 'email ' => $ attributes ['email ' ] ?? 'logged-in-admin@email.com ' ,
31+ 'display_name ' => $ attributes ['display_name ' ] ?? 'Logged In Admin ' ,
32+ 'password ' => password_hash ($ attributes ['password ' ] ?? 'password ' , PASSWORD_ARGON2ID ),
33+ 'status ' => UserRecord::mapStatusToRecord ($ attributes ['status ' ] ?? UserStatus::active ()),
34+ ]);
35+
36+ $ roleRecord = RoleRecord::factory ()->create ([
37+ 'label ' => 'admin ' ,
38+ 'status ' => RoleRecord::mapStatusToRecord (RoleStatus::active ()),
39+ ]);
40+
41+ $ userRecord ->roles ()->attach ($ roleRecord );
42+
43+ $ this ->actingAs ($ userRecord );
44+ }
2445}
You can’t perform that action at this time.
0 commit comments