5
5
use Illuminate \Cache \RateLimiter ;
6
6
use Illuminate \Contracts \Auth \Authenticatable ;
7
7
use Illuminate \Foundation \Auth \User ;
8
+ use Illuminate \Foundation \Testing \RefreshDatabase ;
8
9
use Illuminate \Http \Request ;
9
10
use Illuminate \Support \Facades \Auth ;
10
11
use Illuminate \Support \Facades \Event ;
11
12
use Illuminate \Support \Facades \Schema ;
12
13
use Laravel \Fortify \Contracts \LoginViewResponse ;
13
14
use Laravel \Fortify \Events \TwoFactorAuthenticationChallenged ;
14
15
use Laravel \Fortify \Features ;
15
- use Laravel \Fortify \FortifyServiceProvider ;
16
16
use Laravel \Fortify \LoginRateLimiter ;
17
17
use Laravel \Fortify \TwoFactorAuthenticatable ;
18
18
use Mockery ;
19
19
use PragmaRX \Google2FA \Google2FA ;
20
20
21
21
class AuthenticatedSessionControllerTest extends OrchestraTestCase
22
22
{
23
+ use RefreshDatabase;
24
+
23
25
public function test_the_login_view_is_returned ()
24
26
{
25
27
$ this ->mock (LoginViewResponse::class)
@@ -34,8 +36,6 @@ public function test_the_login_view_is_returned()
34
36
35
37
public function test_user_can_authenticate ()
36
38
{
37
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
38
-
39
39
TestAuthenticationSessionUser::forceCreate ([
40
40
'name ' => 'Taylor Otwell ' ,
41
41
@@ -56,12 +56,6 @@ public function test_user_is_redirected_to_challenge_when_using_two_factor_authe
56
56
57
57
app ('config ' )->set ('auth.providers.users.model ' , TestTwoFactorAuthenticationSessionUser::class);
58
58
59
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
60
-
61
- Schema::table ('users ' , function ($ table ) {
62
- $ table ->text ('two_factor_secret ' )->nullable ();
63
- });
64
-
65
59
TestTwoFactorAuthenticationSessionUser::forceCreate ([
66
60
'name ' => 'Taylor Otwell ' ,
67
61
@@ -89,12 +83,6 @@ public function test_user_is_not_redirected_to_challenge_when_using_two_factor_a
89
83
Features::twoFactorAuthentication (['confirm ' => true ]),
90
84
]);
91
85
92
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
93
-
94
- Schema::table ('users ' , function ($ table ) {
95
- $ table ->text ('two_factor_secret ' )->nullable ();
96
- });
97
-
98
86
TestTwoFactorAuthenticationSessionUser::forceCreate ([
99
87
'name ' => 'Taylor Otwell ' ,
100
88
@@ -120,10 +108,7 @@ public function test_user_is_redirected_to_challenge_when_using_two_factor_authe
120
108
Features::twoFactorAuthentication (['confirm ' => true ]),
121
109
]);
122
110
123
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
124
-
125
111
Schema::table ('users ' , function ($ table ) {
126
- $ table ->text ('two_factor_secret ' )->nullable ();
127
112
$ table ->timestamp ('two_factor_confirmed_at ' )->nullable ();
128
113
});
129
114
@@ -153,12 +138,6 @@ public function test_user_can_authenticate_when_two_factor_challenge_is_disabled
153
138
154
139
app ('config ' )->set ('fortify.features ' , $ features );
155
140
156
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
157
-
158
- Schema::table ('users ' , function ($ table ) {
159
- $ table ->text ('two_factor_secret ' )->nullable ();
160
- });
161
-
162
141
TestTwoFactorAuthenticationSessionUser::forceCreate ([
163
142
'name ' => 'Taylor Otwell ' ,
164
143
@@ -176,8 +155,6 @@ public function test_user_can_authenticate_when_two_factor_challenge_is_disabled
176
155
177
156
public function test_validation_exception_returned_on_failure ()
178
157
{
179
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
180
-
181
158
TestAuthenticationSessionUser::forceCreate ([
182
159
'name ' => 'Taylor Otwell ' ,
183
160
@@ -271,9 +248,6 @@ public function test_two_factor_challenge_can_be_passed_via_code()
271
248
{
272
249
app ('config ' )->set ('auth.providers.users.model ' , TestTwoFactorAuthenticationSessionUser::class);
273
250
274
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
275
- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
276
-
277
251
$ tfaEngine = app (Google2FA::class);
278
252
$ userSecret = $ tfaEngine ->generateSecretKey ();
279
253
$ validOtp = $ tfaEngine ->getCurrentOtp ($ userSecret );
@@ -302,12 +276,6 @@ public function test_two_factor_authentication_preserves_remember_me_selection()
302
276
303
277
app ('config ' )->set ('auth.providers.users.model ' , TestTwoFactorAuthenticationSessionUser::class);
304
278
305
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
306
-
307
- Schema::table ('users ' , function ($ table ) {
308
- $ table ->text ('two_factor_secret ' )->nullable ();
309
- });
310
-
311
279
TestTwoFactorAuthenticationSessionUser::forceCreate ([
312
280
'name ' => 'Taylor Otwell ' ,
313
281
@@ -334,9 +302,6 @@ public function test_two_factor_challenge_fails_for_old_otp_and_zero_window()
334
302
Features::twoFactorAuthentication (['window ' => 0 ]),
335
303
]);
336
304
337
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
338
- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
339
-
340
305
$ tfaEngine = app (Google2FA::class);
341
306
$ userSecret = $ tfaEngine ->generateSecretKey ();
342
307
$ currentTs = $ tfaEngine ->getTimestamp ();
@@ -365,9 +330,6 @@ public function test_two_factor_challenge_can_be_passed_via_recovery_code()
365
330
{
366
331
app ('config ' )->set ('auth.providers.users.model ' , TestTwoFactorAuthenticationSessionUser::class);
367
332
368
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
369
- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
370
-
371
333
$ user = TestTwoFactorAuthenticationSessionUser::forceCreate ([
372
334
'name ' => 'Taylor Otwell ' ,
373
335
@@ -392,9 +354,6 @@ public function test_two_factor_challenge_can_fail_via_recovery_code()
392
354
{
393
355
app ('config ' )->set ('auth.providers.users.model ' , TestTwoFactorAuthenticationSessionUser::class);
394
356
395
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
396
- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
397
-
398
357
$ user = TestTwoFactorAuthenticationSessionUser::forceCreate ([
399
358
'name ' => 'Taylor Otwell ' ,
400
359
@@ -419,9 +378,6 @@ public function test_two_factor_challenge_requires_a_challenged_user()
419
378
{
420
379
app ('config ' )->set ('auth.providers.users.model ' , TestTwoFactorAuthenticationSessionUser::class);
421
380
422
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
423
- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
424
-
425
381
$ response = $ this ->withSession ([])->withoutExceptionHandling ()->get ('/two-factor-challenge ' );
426
382
427
383
$ response ->assertRedirect ('/login ' );
@@ -432,8 +388,6 @@ public function test_case_insensitive_usernames_can_be_used()
432
388
{
433
389
app ('config ' )->set ('fortify.lowercase_usernames ' , true );
434
390
435
- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
436
-
437
391
TestAuthenticationSessionUser::forceCreate ([
438
392
'name ' => 'Taylor Otwell ' ,
439
393
@@ -448,23 +402,12 @@ public function test_case_insensitive_usernames_can_be_used()
448
402
$ response ->assertRedirect ('/home ' );
449
403
}
450
404
451
- protected function getPackageProviders ($ app )
405
+ protected function defineEnvironment ($ app )
452
406
{
453
- return [FortifyServiceProvider::class];
454
- }
455
-
456
- protected function getEnvironmentSetUp ($ app )
457
- {
458
- $ app ['migrator ' ]->path (__DIR__ .'/../database/migrations ' );
459
-
460
- $ app ['config ' ]->set ('auth.providers.users.model ' , TestAuthenticationSessionUser::class);
461
-
462
- $ app ['config ' ]->set ('database.default ' , 'testbench ' );
407
+ parent ::defineEnvironment ($ app );
463
408
464
- $ app ['config ' ]->set ('database.connections.testbench ' , [
465
- 'driver ' => 'sqlite ' ,
466
- 'database ' => ':memory: ' ,
467
- 'prefix ' => '' ,
409
+ $ app ['config ' ]->set ([
410
+ 'auth.providers.users.model ' => TestAuthenticationSessionUser::class,
468
411
]);
469
412
}
470
413
}
0 commit comments