@@ -179,7 +179,7 @@ public function testRouteParamCondition()
179179 */
180180 public function testMiddlewareBefore ()
181181 {
182- $ this ->app ->middleware ('foobar ' , function ($ req , $ res , $ next ) {
182+ $ this ->app ->setMiddleware ('foobar ' , function ($ req , $ res , $ next ) {
183183 $ req ->foobar = "foobar " ;
184184 return $ next ();
185185 });
@@ -197,7 +197,7 @@ public function testMiddlewareBefore()
197197 */
198198 public function testMiddlewareAfter ()
199199 {
200- $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
200+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
201201 $ next ();
202202 return strtoupper ($ res ->body );
203203 });
@@ -215,7 +215,7 @@ public function testMiddlewareAfter()
215215 */
216216 public function testMiddlewareBeforeAndAfter ()
217217 {
218- $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
218+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
219219 $ req ->foobar = "foobar " ;
220220
221221 $ next ();
@@ -236,7 +236,7 @@ public function testMiddlewareBeforeAndAfter()
236236 */
237237 public function testMiddlewareParam ()
238238 {
239- $ this ->app ->middleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
239+ $ this ->app ->setMiddleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
240240 $ req ->str = $ str ;
241241 return $ next ();
242242 });
@@ -254,17 +254,17 @@ public function testMiddlewareParam()
254254 */
255255 public function testMultipleMiddleware ()
256256 {
257- $ this ->app ->middleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
257+ $ this ->app ->setMiddleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
258258 $ req ->str = $ str ;
259259 return $ next ();
260260 });
261261
262- $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
262+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
263263 $ next ();
264264 return strtoupper ($ res ->body );
265265 });
266266
267- $ this ->app ->middleware ('jsonify ' , function ($ req , $ res , $ next ) {
267+ $ this ->app ->setMiddleware ('jsonify ' , function ($ req , $ res , $ next ) {
268268 $ next ();
269269 return $ res ->json (['body ' => $ res ->body ]);
270270 });
@@ -282,7 +282,7 @@ public function testMultipleMiddleware()
282282 */
283283 public function testIgnoringController ()
284284 {
285- $ this ->app ->middleware ('no-controller ' , function ($ req , $ res , $ next ) {
285+ $ this ->app ->setMiddleware ('no-controller ' , function ($ req , $ res , $ next ) {
286286 return "controller ignored " ;
287287 });
288288
@@ -331,7 +331,7 @@ public function testResponseJson()
331331 */
332332 public function testMiddlewareKeepResponseToJson ()
333333 {
334- $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
334+ $ this ->app ->setMiddleware ('uppercase ' , function ($ req , $ res , $ next ) {
335335 $ next ();
336336 return strtoupper ($ res ->body );
337337 });
@@ -345,6 +345,28 @@ public function testMiddlewareKeepResponseToJson()
345345 $ this ->assertResponse ("GET " , "/anything.json " , '{"MESSAGE":"HELLO"} ' , 200 , 'application/json ' );
346346 }
347347
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+
348370 /**
349371 * @runInSeparateProcess
350372 * @preserveGlobalState enabled
@@ -369,7 +391,7 @@ public function testRouteGroupParamCondition()
369391 */
370392 public function testRouteGroupMiddleware ()
371393 {
372- $ this ->app ->middleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
394+ $ this ->app ->setMiddleware ('setStr ' , function ($ req , $ res , $ next , $ str ) {
373395 $ req ->str = $ str ;
374396 return $ next ();
375397 });
@@ -425,7 +447,7 @@ public function testAppBindedToClosure()
425447 {
426448 $ this ->app ->something = "foo " ;
427449 $ this ->app ->foo = "bar " ;
428- $ this ->app ->middleware ('test ' , function ($ req , $ res , $ next ) {
450+ $ this ->app ->setMiddleware ('test ' , function ($ req , $ res , $ next ) {
429451 $ next ();
430452 return strtoupper ($ this ->something .$ res ->body );
431453 });
0 commit comments