1515namespace Authorization \Test \TestCase \Middleware ;
1616
1717use Authorization \AuthorizationServiceInterface ;
18+ use Authorization \AuthorizationServiceProviderInterface ;
1819use Authorization \Exception \AuthorizationRequiredException ;
1920use Authorization \Exception \Exception ;
2021use Authorization \IdentityDecorator ;
2122use Authorization \IdentityInterface ;
2223use Authorization \Middleware \AuthorizationMiddleware ;
23- use Cake \Core \HttpApplicationInterface ;
2424use Cake \Http \Response ;
2525use Cake \Http \ServerRequest ;
2626use Cake \TestSuite \TestCase ;
@@ -78,13 +78,10 @@ public function testInvokeAuthorizationRequiredError()
7878 public function testInvokeApp ()
7979 {
8080 $ service = $ this ->createMock (AuthorizationServiceInterface::class);
81-
82- $ application = $ this ->getMockBuilder (HttpApplicationInterface::class)
83- ->setMethods (['authorization ' , 'middleware ' , 'routes ' , 'bootstrap ' , '__invoke ' ])
84- ->getMock ();
85- $ application
81+ $ provider = $ this ->createMock (AuthorizationServiceProviderInterface::class);
82+ $ provider
8683 ->expects ($ this ->once ())
87- ->method ('authorization ' )
84+ ->method ('getAuthorizationService ' )
8885 ->with (
8986 $ this ->isInstanceOf (ServerRequestInterface::class),
9087 $ this ->isInstanceOf (ResponseInterface::class)
@@ -97,7 +94,7 @@ public function testInvokeApp()
9794 return $ request ;
9895 };
9996
100- $ middleware = new AuthorizationMiddleware ($ application , ['requireAuthorizationCheck ' => false ]);
97+ $ middleware = new AuthorizationMiddleware ($ provider , ['requireAuthorizationCheck ' => false ]);
10198
10299 $ result = $ middleware ($ request , $ response , $ next );
103100
@@ -106,40 +103,12 @@ public function testInvokeApp()
106103 $ this ->assertNull ($ result ->getAttribute ('identity ' ));
107104 }
108105
109- public function testInvokeAppMissing ()
110- {
111- $ service = $ this ->createMock (AuthorizationServiceInterface::class);
112-
113- $ application = $ this ->getMockBuilder (HttpApplicationInterface::class)
114- ->setMethods (['middleware ' , 'routes ' , 'bootstrap ' , '__invoke ' ])
115- ->getMock ();
116-
117- $ request = new ServerRequest ();
118- $ response = new Response ();
119- $ next = function ($ request ) {
120- return $ request ;
121- };
122-
123- $ middleware = new AuthorizationMiddleware ($ application , ['requireAuthorizationCheck ' => false ]);
124-
125- $ this ->expectException (RuntimeException::class);
126- $ this ->expectExceptionMessage ('Method `authorization` has not been defined in your `Application` class. ' );
127-
128- $ result = $ middleware ($ request , $ response , $ next );
129- }
130-
131106 public function testInvokeAppInvalid ()
132107 {
133- $ application = $ this ->getMockBuilder (HttpApplicationInterface::class)
134- ->setMethods (['middleware ' , 'routes ' , 'bootstrap ' , '__invoke ' ])
135- ->getMock ();
136-
137- $ application = $ this ->getMockBuilder (HttpApplicationInterface::class)
138- ->setMethods (['authorization ' , 'middleware ' , 'routes ' , 'bootstrap ' , '__invoke ' ])
139- ->getMock ();
140- $ application
108+ $ provider = $ this ->createMock (AuthorizationServiceProviderInterface::class);
109+ $ provider
141110 ->expects ($ this ->once ())
142- ->method ('authorization ' )
111+ ->method ('getAuthorizationService ' )
143112 ->with (
144113 $ this ->isInstanceOf (ServerRequestInterface::class),
145114 $ this ->isInstanceOf (ResponseInterface::class)
@@ -152,11 +121,11 @@ public function testInvokeAppInvalid()
152121 return $ request ;
153122 };
154123
155- $ middleware = new AuthorizationMiddleware ($ application , ['requireAuthorizationCheck ' => false ]);
124+ $ middleware = new AuthorizationMiddleware ($ provider , ['requireAuthorizationCheck ' => false ]);
156125
157126 $ this ->expectException (RuntimeException::class);
158127 $ this ->expectExceptionMessage (
159- 'Invalid service returned from `authorization` method . ' .
128+ 'Invalid service returned from the provider . ' .
160129 '`stdClass` does not implement `Authorization\AuthorizationServiceInterface`. '
161130 );
162131
@@ -176,7 +145,7 @@ public function testInvokeInvalid()
176145 $ this ->expectException (InvalidArgumentException::class);
177146 $ this ->expectExceptionMessage (
178147 'Subject must be an instance of `Authorization\AuthorizationServiceInterface` ' .
179- 'or `Cake\Core\HttpApplicationInterface `, `stdClass` given. '
148+ 'or `Authorization\AuthorizationServiceProviderInterface `, `stdClass` given. '
180149 );
181150
182151 $ middleware = new AuthorizationMiddleware (new stdClass ());
0 commit comments