File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Feature ;
6+
7+ use Contexts \Authorization \Domain \UserIdentity \Models \UserStatus ;
8+ use Contexts \Authorization \Infrastructure \Records \UserRecord ;
9+
10+ trait AuthenticationSupport
11+ {
12+ protected function loginAsUser (array $ attributes = []): void
13+ {
14+ $ plainPassword = $ attributes ['password ' ] ?? 'password ' ;
15+ $ userRecord = UserRecord::factory ()->create ([
16+ 'email ' => $ attributes ['email ' ] ?? 'logged-in-user@email.com ' ,
17+ 'display_name ' => $ attributes ['display_name ' ] ?? 'Logged In User ' ,
18+ 'password ' => password_hash ($ plainPassword , PASSWORD_ARGON2ID ),
19+ 'status ' => UserRecord::mapStatusToRecord ($ attributes ['status ' ] ?? UserStatus::active ()),
20+ ]);
21+
22+ $ this ->actingAs ($ userRecord );
23+ }
24+ }
Original file line number Diff line number Diff line change 33declare (strict_types=1 );
44
55use Illuminate \Foundation \Testing \RefreshDatabase ;
6+ use Tests \Feature \AuthenticationSupport ;
67
78/*
89|--------------------------------------------------------------------------
1516|
1617*/
1718
18- uses (Tests \TestCase::class, RefreshDatabase::class)->in (__DIR__ .'/../contexts/*/Tests/Feature ' );
19- uses (Tests \TestCase::class, RefreshDatabase::class)->in (__DIR__ .'/../tests/Feature ' );
19+ uses (Tests \TestCase::class, RefreshDatabase::class, AuthenticationSupport::class )->in (__DIR__ .'/../contexts/*/Tests/Feature ' );
20+ uses (Tests \TestCase::class, RefreshDatabase::class, AuthenticationSupport::class )->in (__DIR__ .'/../tests/Feature ' );
2021
2122/*
2223|--------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments