@@ -124,8 +124,13 @@ public function testUserIsAuthenticated()
124
124
125
125
/**
126
126
* Test if authentication is applied based on request attribute, when middleware is called as PSR-15 middleware.
127
+ *
128
+ * @dataProvider provideDataForPsr15Test
129
+ * @param bool $applyOnExit
127
130
*/
128
- public function testUserIsAuthenticatedPsr15 ()
131
+ public function testUserIsAuthenticatedPsr15 (
132
+ bool $ applyOnExit
133
+ )
129
134
{
130
135
$ user = new AuthenticatedUser (
131
136
1 ,
@@ -178,10 +183,15 @@ public function testUserIsAuthenticatedPsr15()
178
183
]
179
184
));
180
185
181
- $ middleware = new ApplyAuthenticationMiddleware (new RequestValueContainer ('test_transport ' ));
182
- $ this ->assertFalse ($ middleware ->applyOnExit ());
186
+ $ middleware = new ApplyAuthenticationMiddleware (
187
+ new RequestValueContainer ('test_transport ' ),
188
+ $ applyOnExit
189
+ );
190
+
191
+ $ this ->assertSame ($ applyOnExit , $ middleware ->applyOnExit ());
183
192
184
- $ response = $ middleware ->process ($ request ,
193
+ $ response = $ middleware ->process (
194
+ $ request ,
185
195
new class implements RequestHandlerInterface
186
196
{
187
197
public function handle (ServerRequestInterface $ request ): ResponseInterface
@@ -200,6 +210,14 @@ public function handle(ServerRequestInterface $request): ResponseInterface
200
210
$ this ->assertContains ('my-session-id ' , $ setCookieHeader );
201
211
}
202
212
213
+ public function provideDataForPsr15Test (): array
214
+ {
215
+ return [
216
+ [true ],
217
+ [false ],
218
+ ];
219
+ }
220
+
203
221
/**
204
222
* Test if next middleware in stack is called.
205
223
*/
@@ -232,6 +250,34 @@ function (
232
250
$ this ->assertSame ('Yes, found! ' , $ response ->getHeaderLine ('X-Test ' ));
233
251
}
234
252
253
+ public function testProcessIsCalled ()
254
+ {
255
+ $ middlware = new ApplyAuthenticationMiddleware (
256
+ new RequestValueContainer ('test_transport ' )
257
+ );
258
+
259
+ $ handler = new class implements RequestHandlerInterface
260
+ {
261
+ private $ handleIsCalled = false ;
262
+
263
+ public function handle (ServerRequestInterface $ request ): ResponseInterface
264
+ {
265
+ $ this ->handleIsCalled = true ;
266
+ return (new ResponseFactory ())->createResponse ();
267
+ }
268
+
269
+ public function isHandleCalled (): bool
270
+ {
271
+ return $ this ->handleIsCalled ;
272
+ }
273
+ };
274
+
275
+ $ response = $ middlware ->process ($ this ->request , $ handler );
276
+ $ this ->assertInstanceOf (ResponseInterface::class, $ response );
277
+
278
+ $ this ->assertTrue ($ handler ->isHandleCalled ());
279
+ }
280
+
235
281
/**
236
282
* Test if authentication is applied based on request attribute.
237
283
*/
0 commit comments