22
33namespace Dingo \Api \Tests \Auth \Provider ;
44
5- use Mockery as m ;
6- use Illuminate \Http \Request ;
7- use PHPUnit \Framework \TestCase ;
85use Dingo \Api \Auth \Provider \JWT ;
6+ use Dingo \Api \Routing \Route ;
7+ use Dingo \Api \Tests \BaseTestCase ;
8+ use Illuminate \Http \Request ;
9+ use Mockery as m ;
10+ use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
11+ use Symfony \Component \HttpKernel \Exception \UnauthorizedHttpException ;
912use Tymon \JWTAuth \Exceptions \JWTException ;
1013
11- class JWTTest extends TestCase
14+ class JWTTest extends BaseTestCase
1215{
1316 protected $ auth ;
1417 protected $ provider ;
1518
16- public function setUp ()
19+ public function setUp (): void
1720 {
21+ parent ::setUp ();
22+
1823 $ this ->auth = m::mock ('Tymon\JWTAuth\JWTAuth ' );
1924 $ this ->provider = new JWT ($ this ->auth );
2025 }
2126
22- public function tearDown ()
23- {
24- m::close ();
25- }
26-
27- /**
28- * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
29- */
3027 public function testValidatingAuthorizationHeaderFailsAndThrowsException ()
3128 {
29+ $ this ->expectException (BadRequestHttpException::class);
30+
3231 $ request = Request::create ('foo ' , 'GET ' );
33- $ this ->provider ->authenticate ($ request , m::mock (\ Dingo \ Api \ Routing \ Route::class));
32+ $ this ->provider ->authenticate ($ request , m::mock (Route::class));
3433 }
3534
36- /**
37- * @expectedException \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
38- */
3935 public function testAuthenticatingFailsAndThrowsException ()
4036 {
37+ $ this ->expectException (UnauthorizedHttpException::class);
38+
4139 $ request = Request::create ('foo ' , 'GET ' );
4240 $ request ->headers ->set ('authorization ' , 'Bearer foo ' );
4341
4442 $ this ->auth ->shouldReceive ('setToken ' )->with ('foo ' )->andReturn (m::self ());
4543 $ this ->auth ->shouldReceive ('authenticate ' )->once ()->andThrow (new JWTException ('foo ' ));
4644
47- $ this ->provider ->authenticate ($ request , m::mock (\ Dingo \ Api \ Routing \ Route::class));
45+ $ this ->provider ->authenticate ($ request , m::mock (Route::class));
4846 }
4947
5048 public function testAuthenticatingSucceedsAndReturnsUserObject ()
@@ -55,7 +53,7 @@ public function testAuthenticatingSucceedsAndReturnsUserObject()
5553 $ this ->auth ->shouldReceive ('setToken ' )->with ('foo ' )->andReturn (m::self ());
5654 $ this ->auth ->shouldReceive ('authenticate ' )->once ()->andReturn ((object ) ['id ' => 1 ]);
5755
58- $ this ->assertSame (1 , $ this ->provider ->authenticate ($ request , m::mock (\ Dingo \ Api \ Routing \ Route::class))->id );
56+ $ this ->assertSame (1 , $ this ->provider ->authenticate ($ request , m::mock (Route::class))->id );
5957 }
6058
6159 public function testAuthenticatingWithQueryStringSucceedsAndReturnsUserObject ()
@@ -65,6 +63,6 @@ public function testAuthenticatingWithQueryStringSucceedsAndReturnsUserObject()
6563 $ this ->auth ->shouldReceive ('setToken ' )->with ('foo ' )->andReturn (m::self ());
6664 $ this ->auth ->shouldReceive ('authenticate ' )->once ()->andReturn ((object ) ['id ' => 1 ]);
6765
68- $ this ->assertSame (1 , $ this ->provider ->authenticate ($ request , m::mock (\ Dingo \ Api \ Routing \ Route::class))->id );
66+ $ this ->assertSame (1 , $ this ->provider ->authenticate ($ request , m::mock (Route::class))->id );
6967 }
7068}
0 commit comments