@@ -179,7 +179,7 @@ public function testRouteParamCondition()
179
179
*/
180
180
public function testMiddlewareBefore ()
181
181
{
182
- $ this ->app ->middleware ('foobar ' , function ($ req , $ res , $ next ) {
182
+ $ this ->app ->setMiddleware ('foobar ' , function ($ req , $ res , $ next ) {
183
183
$ req ->foobar = "foobar " ;
184
184
return $ next ();
185
185
});
@@ -197,7 +197,7 @@ public function testMiddlewareBefore()
197
197
*/
198
198
public function testMiddlewareAfter ()
199
199
{
200
- $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
200
+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
201
201
$ next ();
202
202
return strtoupper ($ res ->body );
203
203
});
@@ -215,7 +215,7 @@ public function testMiddlewareAfter()
215
215
*/
216
216
public function testMiddlewareBeforeAndAfter ()
217
217
{
218
- $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
218
+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
219
219
$ req ->foobar = "foobar " ;
220
220
221
221
$ next ();
@@ -236,7 +236,7 @@ public function testMiddlewareBeforeAndAfter()
236
236
*/
237
237
public function testMiddlewareParam ()
238
238
{
239
- $ this ->app ->middleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
239
+ $ this ->app ->setMiddleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
240
240
$ req ->str = $ str ;
241
241
return $ next ();
242
242
});
@@ -254,17 +254,17 @@ public function testMiddlewareParam()
254
254
*/
255
255
public function testMultipleMiddleware ()
256
256
{
257
- $ this ->app ->middleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
257
+ $ this ->app ->setMiddleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
258
258
$ req ->str = $ str ;
259
259
return $ next ();
260
260
});
261
261
262
- $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
262
+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
263
263
$ next ();
264
264
return strtoupper ($ res ->body );
265
265
});
266
266
267
- $ this ->app ->middleware ('jsonify ' , function ($ req , $ res , $ next ) {
267
+ $ this ->app ->setMiddleware ('jsonify ' , function ($ req , $ res , $ next ) {
268
268
$ next ();
269
269
return $ res ->json (['body ' => $ res ->body ]);
270
270
});
@@ -282,7 +282,7 @@ public function testMultipleMiddleware()
282
282
*/
283
283
public function testIgnoringController ()
284
284
{
285
- $ this ->app ->middleware ('no-controller ' , function ($ req , $ res , $ next ) {
285
+ $ this ->app ->setMiddleware ('no-controller ' , function ($ req , $ res , $ next ) {
286
286
return "controller ignored " ;
287
287
});
288
288
@@ -331,7 +331,7 @@ public function testResponseJson()
331
331
*/
332
332
public function testMiddlewareKeepResponseToJson ()
333
333
{
334
- $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
334
+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
335
335
$ next ();
336
336
return strtoupper ($ res ->body );
337
337
});
@@ -345,6 +345,28 @@ public function testMiddlewareKeepResponseToJson()
345
345
$ this ->assertResponse ("GET " , "/anything.json " , '{"MESSAGE":"HELLO"} ' , 200 , 'application/json ' );
346
346
}
347
347
348
+ /**
349
+ * @runInSeparateProcess
350
+ * @preserveGlobalState enabled
351
+ */
352
+ public function testGlobalMiddleware ()
353
+ {
354
+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
355
+ $ next ();
356
+ return strtoupper ($ res ->body );
357
+ });
358
+
359
+ $ this ->app ->useMiddleware ('uppercase ' );
360
+
361
+ $ this ->app ->get ('/anything.json ' , function () {
362
+ return [
363
+ 'message ' => 'hello '
364
+ ];
365
+ });
366
+
367
+ $ this ->assertResponse ("GET " , "/anything.json " , '{"MESSAGE":"HELLO"} ' , 200 , 'application/json ' );
368
+ }
369
+
348
370
/**
349
371
* @runInSeparateProcess
350
372
* @preserveGlobalState enabled
@@ -369,7 +391,7 @@ public function testRouteGroupParamCondition()
369
391
*/
370
392
public function testRouteGroupMiddleware ()
371
393
{
372
- $ this ->app ->middleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
394
+ $ this ->app ->setMiddleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
373
395
$ req ->str = $ str ;
374
396
return $ next ();
375
397
});
@@ -425,7 +447,7 @@ public function testAppBindedToClosure()
425
447
{
426
448
$ this ->app ->something = "foo " ;
427
449
$ this ->app ->foo = "bar " ;
428
- $ this ->app ->middleware ('test ' , function ($ req , $ res , $ next ) {
450
+ $ this ->app ->setMiddleware ('test ' , function ($ req , $ res , $ next ) {
429
451
$ next ();
430
452
return strtoupper ($ this ->something .$ res ->body );
431
453
});
0 commit comments