11<?php
22
3- namespace Laravel \Sanctum \Tests ;
3+ namespace Laravel \Sanctum \Tests \ Feature ;
44
55use DateTimeInterface ;
66use Illuminate \Auth \EloquentUserProvider ;
1515use Laravel \Sanctum \HasApiTokens ;
1616use Laravel \Sanctum \PersonalAccessToken ;
1717use Laravel \Sanctum \Sanctum ;
18- use Laravel \Sanctum \SanctumServiceProvider ;
1918use Mockery ;
19+ use Orchestra \Testbench \Concerns \WithWorkbench ;
2020use Orchestra \Testbench \TestCase ;
2121use stdClass ;
2222
2323class GuardTest extends TestCase
2424{
25- protected function getEnvironmentSetUp ($ app )
26- {
27- $ app ['config ' ]->set ('database.default ' , 'testbench ' );
28-
29- $ app ['config ' ]->set ('database.connections.testbench ' , [
30- 'driver ' => 'sqlite ' ,
31- 'database ' => ':memory: ' ,
32- 'prefix ' => '' ,
33- ]);
34- }
25+ use WithWorkbench;
3526
36- public function tearDown (): void
27+ protected function defineEnvironment ( $ app )
3728 {
38- parent ::tearDown ();
39-
40- Mockery::close ();
29+ $ app ['config ' ]->set ('database.default ' , 'testing ' );
4130 }
4231
4332 public function test_authentication_is_attempted_with_web_middleware ()
@@ -62,7 +51,7 @@ public function test_authentication_is_attempted_with_web_middleware()
6251
6352 public function test_authentication_is_attempted_with_token_if_no_session_present ()
6453 {
65- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
54+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
6655
6756 $ factory = Mockery::mock (AuthFactory::class);
6857
@@ -86,8 +75,8 @@ public function test_authentication_is_attempted_with_token_if_no_session_presen
8675
8776 public function test_authentication_with_token_fails_if_expired ()
8877 {
89- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
90- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
78+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
79+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
9180
9281 $ factory = Mockery::mock (AuthFactory::class);
9382
@@ -126,8 +115,8 @@ public function test_authentication_with_token_fails_if_expired()
126115
127116 public function test_authentication_with_token_fails_if_expires_at_has_passed ()
128117 {
129- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
130- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
118+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
119+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
131120
132121 $ factory = Mockery::mock (AuthFactory::class);
133122
@@ -166,8 +155,8 @@ public function test_authentication_with_token_fails_if_expires_at_has_passed()
166155
167156 public function test_authentication_with_token_succeeds_if_expires_at_not_passed ()
168157 {
169- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
170- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
158+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
159+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
171160
172161 $ factory = Mockery::mock (AuthFactory::class);
173162
@@ -206,8 +195,8 @@ public function test_authentication_with_token_succeeds_if_expires_at_not_passed
206195
207196 public function test_authentication_is_successful_with_token_if_no_session_present ()
208197 {
209- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
210- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
198+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
199+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
211200
212201 $ factory = Mockery::mock (AuthFactory::class);
213202
@@ -247,8 +236,8 @@ public function test_authentication_is_successful_with_token_if_no_session_prese
247236
248237 public function test_authentication_with_token_fails_if_user_provider_is_invalid ()
249238 {
250- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
251- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
239+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
240+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
252241
253242 config (['auth.guards.sanctum.provider ' => 'users ' ]);
254243 config (['auth.providers.users.model ' => 'App\Models\User ' ]);
@@ -289,8 +278,8 @@ public function test_authentication_with_token_fails_if_user_provider_is_invalid
289278 */
290279 public function test_authentication_with_token_fails_if_token_has_invalid_format ($ invalidToken )
291280 {
292- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
293- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
281+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
282+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
294283
295284 $ factory = Mockery::mock (AuthFactory::class);
296285
@@ -328,8 +317,8 @@ public function test_authentication_with_token_fails_if_token_has_invalid_format
328317
329318 public function test_authentication_is_successful_with_token_if_user_provider_is_valid ()
330319 {
331- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
332- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
320+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
321+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
333322
334323 config (['auth.guards.sanctum.provider ' => 'users ' ]);
335324 config (['auth.providers.users.model ' => User::class]);
@@ -367,8 +356,8 @@ public function test_authentication_is_successful_with_token_if_user_provider_is
367356
368357 public function test_authentication_fails_if_callback_returns_false ()
369358 {
370- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
371- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
359+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
360+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
372361
373362 config (['auth.guards.sanctum.provider ' => 'users ' ]);
374363 config (['auth.providers.users.model ' => User::class]);
@@ -408,8 +397,8 @@ public function test_authentication_fails_if_callback_returns_false()
408397
409398 public function test_authentication_is_successful_with_token_in_custom_header ()
410399 {
411- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
412- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
400+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
401+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
413402
414403 $ factory = Mockery::mock (AuthFactory::class);
415404
@@ -455,8 +444,8 @@ public function test_authentication_is_successful_with_token_in_custom_header()
455444
456445 public function test_authentication_fails_with_token_in_authorization_header_when_using_custom_header ()
457446 {
458- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
459- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
447+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
448+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
460449
461450 $ factory = Mockery::mock (AuthFactory::class);
462451
@@ -500,8 +489,8 @@ public function test_authentication_fails_with_token_in_authorization_header_whe
500489
501490 public function test_authentication_fails_with_token_in_custom_header_when_using_default_authorization_header ()
502491 {
503- $ this ->loadLaravelMigrations (['--database ' => 'testbench ' ]);
504- $ this ->artisan ('migrate ' , ['--database ' => 'testbench ' ])->run ();
492+ $ this ->loadLaravelMigrations (['--database ' => 'testing ' ]);
493+ $ this ->artisan ('migrate ' , ['--database ' => 'testing ' ])->run ();
505494
506495 $ factory = Mockery::mock (AuthFactory::class);
507496
@@ -537,11 +526,6 @@ public function test_authentication_fails_with_token_in_custom_header_when_using
537526 $ this ->assertNull ($ returnedUser );
538527 }
539528
540- protected function getPackageProviders ($ app )
541- {
542- return [SanctumServiceProvider::class];
543- }
544-
545529 public static function invalidTokenDataProvider (): array
546530 {
547531 return [
0 commit comments