44
55use Mockery as m ;
66use Dingo \Api \Http \Request ;
7+ use Dingo \Api \Routing \Route ;
78use PHPUnit_Framework_TestCase ;
89use Illuminate \Container \Container ;
910use Dingo \Api \Http \Middleware \Auth ;
11+ use Dingo \Api \Tests \Stubs \RoutingAdapterStub ;
1012use Symfony \Component \HttpKernel \Exception \UnauthorizedHttpException ;
1113
1214class AuthTest extends PHPUnit_Framework_TestCase
1315{
1416 public function setUp ()
1517 {
18+ $ this ->container = new Container ;
19+ $ this ->adapter = new RoutingAdapterStub ;
1620 $ this ->router = m::mock ('Dingo\Api\Routing\Router ' );
1721 $ this ->auth = m::mock ('Dingo\Api\Auth\Auth ' );
1822 $ this ->middleware = new Auth ($ this ->router , $ this ->auth );
@@ -22,9 +26,12 @@ public function testProtectedRouteFiresAuthenticationAndPasses()
2226 {
2327 $ request = Request::create ('test ' , 'GET ' );
2428
25- $ route = m::mock ('Dingo\Api\Routing\Route ' );
26- $ route ->shouldReceive ('isProtected ' )->once ()->andReturn (true );
27- $ route ->shouldReceive ('getAuthProviders ' )->once ()->andReturn ([]);
29+ $ route = new Route ($ this ->adapter , $ this ->container , $ request , [
30+ 'uri ' => '/test ' ,
31+ 'action ' => [
32+ 'providers ' => []
33+ ]
34+ ]);
2835
2936 $ this ->auth ->shouldReceive ('check ' )->once ()->with (false )->andReturn (false );
3037 $ this ->auth ->shouldReceive ('authenticate ' )->once ()->with ([])->andReturn (null );
@@ -40,8 +47,12 @@ public function testProtectedRouteAlreadyLoggedIn()
4047 {
4148 $ request = Request::create ('test ' , 'GET ' );
4249
43- $ route = m::mock ('Dingo\Api\Routing\Route ' );
44- $ route ->shouldReceive ('isProtected ' )->once ()->andReturn (true );
50+ $ route = new Route ($ this ->adapter , $ this ->container , $ request , [
51+ 'uri ' => '/test ' ,
52+ 'action ' => [
53+ 'providers ' => []
54+ ]
55+ ]);
4556
4657 $ this ->auth ->shouldReceive ('check ' )->once ()->with (false )->andReturn (true );
4758
@@ -61,9 +72,12 @@ public function testAuthenticationFailsAndExceptionIsThrown()
6172
6273 $ request = Request::create ('test ' , 'GET ' );
6374
64- $ route = m::mock ('Dingo\Api\Routing\Route ' );
65- $ route ->shouldReceive ('isProtected ' )->once ()->andReturn (true );
66- $ route ->shouldReceive ('getAuthProviders ' )->once ()->andReturn ([]);
75+ $ route = new Route ($ this ->adapter , $ this ->container , $ request , [
76+ 'uri ' => '/test ' ,
77+ 'action ' => [
78+ 'providers ' => []
79+ ]
80+ ]);
6781
6882 $ this ->auth ->shouldReceive ('check ' )->once ()->with (false )->andReturn (false );
6983 $ this ->auth ->shouldReceive ('authenticate ' )->once ()->with ([])->andThrow ($ exception );
0 commit comments