@@ -39,8 +39,11 @@ public function testSetErrorHandler()
3939$ callableResolver =$ app ->getCallableResolver ();
4040$ logger =$ this ->getMockLogger ();
4141
42- $ mw =new RoutingMiddleware ($ app ->getRouteResolver (),$ app ->getRouteCollector ()->getRouteParser ());
43- $ app ->add ($ mw );
42+ $ routingMiddleware =new RoutingMiddleware (
43+ $ app ->getRouteResolver (),
44+ $ app ->getRouteCollector ()->getRouteParser ()
45+ );
46+ $ app ->add ($ routingMiddleware );
4447
4548$ exception = HttpNotFoundException::class;
4649$ handler = (function () {
@@ -49,9 +52,16 @@ public function testSetErrorHandler()
4952return $ response ;
5053 })->bindTo ($ this );
5154
52- $ mw2 =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
53- $ mw2 ->setErrorHandler ($ exception ,$ handler );
54- $ app ->add ($ mw2 );
55+ $ errorMiddleware =new ErrorMiddleware (
56+ $ callableResolver ,
57+ $ this ->getResponseFactory (),
58+ false ,
59+ false ,
60+ false ,
61+ $ logger
62+ );
63+ $ errorMiddleware ->setErrorHandler ($ exception ,$ handler );
64+ $ app ->add ($ errorMiddleware );
5565
5666$ request =$ this ->createServerRequest ('/foo/baz/ ' );
5767$ app ->run ($ request );
@@ -66,18 +76,28 @@ public function testSetDefaultErrorHandler()
6676$ callableResolver =$ app ->getCallableResolver ();
6777$ logger =$ this ->getMockLogger ();
6878
69- $ mw =new RoutingMiddleware ($ app ->getRouteResolver (),$ app ->getRouteCollector ()->getRouteParser ());
70- $ app ->add ($ mw );
79+ $ routingMiddleware =new RoutingMiddleware (
80+ $ app ->getRouteResolver (),
81+ $ app ->getRouteCollector ()->getRouteParser ()
82+ );
83+ $ app ->add ($ routingMiddleware );
7184
7285$ handler = (function () {
7386$ response =$ this ->createResponse ();
7487$ response ->getBody ()->write ('Oops.. ' );
7588return $ response ;
7689 })->bindTo ($ this );
7790
78- $ mw2 =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
79- $ mw2 ->setDefaultErrorHandler ($ handler );
80- $ app ->add ($ mw2 );
91+ $ errorMiddleware =new ErrorMiddleware (
92+ $ callableResolver ,
93+ $ this ->getResponseFactory (),
94+ false ,
95+ false ,
96+ false ,
97+ $ logger
98+ );
99+ $ errorMiddleware ->setDefaultErrorHandler ($ handler );
100+ $ app ->add ($ errorMiddleware );
81101
82102$ request =$ this ->createServerRequest ('/foo/baz/ ' );
83103$ app ->run ($ request );
@@ -94,9 +114,16 @@ public function testSetDefaultErrorHandlerThrowsException()
94114$ callableResolver =$ app ->getCallableResolver ();
95115$ logger =$ this ->getMockLogger ();
96116
97- $ mw =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
98- $ mw ->setDefaultErrorHandler ('Uncallable ' );
99- $ mw ->getDefaultErrorHandler ();
117+ $ errorMiddleware =new ErrorMiddleware (
118+ $ callableResolver ,
119+ $ this ->getResponseFactory (),
120+ false ,
121+ false ,
122+ false ,
123+ $ logger
124+ );
125+ $ errorMiddleware ->setDefaultErrorHandler ('Uncallable ' );
126+ $ errorMiddleware ->getDefaultErrorHandler ();
100127 }
101128
102129public function testGetErrorHandlerWillReturnDefaultErrorHandlerForUnhandledExceptions ()
@@ -118,21 +145,21 @@ public function testSuperclassExceptionHandlerHandlesExceptionWithSubclassExactM
118145$ app =new App ($ responseFactory );
119146$ callableResolver =$ app ->getCallableResolver ();
120147$ logger =$ this ->getMockLogger ();
121- $ mw =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
148+ $ middleware =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
122149$ app ->add (function ($ request ,$ handler ) {
123150throw new LogicException ('This is a LogicException... ' );
124151 });
125- $ mw ->setErrorHandler (LogicException::class, (function (ServerRequestInterface $ request ,$ exception ) {
152+ $ middleware ->setErrorHandler (LogicException::class, (function (ServerRequestInterface $ request ,$ exception ) {
126153$ response =$ this ->createResponse ();
127154$ response ->getBody ()->write ($ exception ->getMessage ());
128155return $ response ;
129156 })->bindTo ($ this ),true );// - true; handle subclass but also LogicException explicitly
130- $ mw ->setDefaultErrorHandler ((function () {
157+ $ middleware ->setDefaultErrorHandler ((function () {
131158$ response =$ this ->createResponse ();
132159$ response ->getBody ()->write ('Oops.. ' );
133160return $ response ;
134161 })->bindTo ($ this ));
135- $ app ->add ($ mw );
162+ $ app ->add ($ middleware );
136163$ app ->get ('/foo ' ,function (ServerRequestInterface $ request ,ResponseInterface $ response ) {
137164$ response ->getBody ()->write ('... ' );
138165return $ response ;
@@ -149,25 +176,25 @@ public function testSuperclassExceptionHandlerHandlesSubclassException()
149176$ callableResolver =$ app ->getCallableResolver ();
150177$ logger =$ this ->getMockLogger ();
151178
152- $ mw =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
179+ $ middleware =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
153180
154181$ app ->add (function ($ request ,$ handler ) {
155182throw new InvalidArgumentException ('This is a subclass of LogicException... ' );
156183 });
157184
158- $ mw ->setErrorHandler (LogicException::class, (function (ServerRequestInterface $ request ,$ exception ) {
185+ $ middleware ->setErrorHandler (LogicException::class, (function (ServerRequestInterface $ request ,$ exception ) {
159186$ response =$ this ->createResponse ();
160187$ response ->getBody ()->write ($ exception ->getMessage ());
161188return $ response ;
162189 })->bindTo ($ this ),true );// - true; handle subclass
163190
164- $ mw ->setDefaultErrorHandler ((function () {
191+ $ middleware ->setDefaultErrorHandler ((function () {
165192$ response =$ this ->createResponse ();
166193$ response ->getBody ()->write ('Oops.. ' );
167194return $ response ;
168195 })->bindTo ($ this ));
169196
170- $ app ->add ($ mw );
197+ $ app ->add ($ middleware );
171198
172199$ app ->get ('/foo ' ,function (ServerRequestInterface $ request ,ResponseInterface $ response ) {
173200$ response ->getBody ()->write ('... ' );
@@ -187,25 +214,25 @@ public function testSuperclassExceptionHandlerDoesNotHandleSubclassException()
187214$ callableResolver =$ app ->getCallableResolver ();
188215$ logger =$ this ->getMockLogger ();
189216
190- $ mw =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
217+ $ middleware =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
191218
192219$ app ->add (function ($ request ,$ handler ) {
193220throw new InvalidArgumentException ('This is a subclass of LogicException... ' );
194221 });
195222
196- $ mw ->setErrorHandler (LogicException::class, (function (ServerRequestInterface $ request ,$ exception ) {
223+ $ middleware ->setErrorHandler (LogicException::class, (function (ServerRequestInterface $ request ,$ exception ) {
197224$ response =$ this ->createResponse ();
198225$ response ->getBody ()->write ($ exception ->getMessage ());
199226return $ response ;
200227 })->bindTo ($ this ),false );// - false; don't handle subclass
201228
202- $ mw ->setDefaultErrorHandler ((function () {
229+ $ middleware ->setDefaultErrorHandler ((function () {
203230$ response =$ this ->createResponse ();
204231$ response ->getBody ()->write ('Oops.. ' );
205232return $ response ;
206233 })->bindTo ($ this ));
207234
208- $ app ->add ($ mw );
235+ $ app ->add ($ middleware );
209236
210237$ app ->get ('/foo ' ,function (ServerRequestInterface $ request ,ResponseInterface $ response ) {
211238$ response ->getBody ()->write ('... ' );
@@ -225,7 +252,7 @@ public function testHandleMultipleExceptionsAddedAsArray()
225252$ callableResolver =$ app ->getCallableResolver ();
226253$ logger =$ this ->getMockLogger ();
227254
228- $ mw =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
255+ $ middleware =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
229256
230257$ app ->add (function ($ request ,$ handler ) {
231258throw new InvalidArgumentException ('This is an invalid argument exception... ' );
@@ -237,15 +264,15 @@ public function testHandleMultipleExceptionsAddedAsArray()
237264return $ response ;
238265 });
239266
240- $ mw ->setErrorHandler ([LogicException::class, InvalidArgumentException::class],$ handler ->bindTo ($ this ));
267+ $ middleware ->setErrorHandler ([LogicException::class, InvalidArgumentException::class],$ handler ->bindTo ($ this ));
241268
242- $ mw ->setDefaultErrorHandler ((function () {
269+ $ middleware ->setDefaultErrorHandler ((function () {
243270$ response =$ this ->createResponse ();
244271$ response ->getBody ()->write ('Oops.. ' );
245272return $ response ;
246273 })->bindTo ($ this ));
247274
248- $ app ->add ($ mw );
275+ $ app ->add ($ middleware );
249276
250277$ app ->get ('/foo ' ,function (ServerRequestInterface $ request ,ResponseInterface $ response ) {
251278$ response ->getBody ()->write ('... ' );
@@ -265,19 +292,19 @@ public function testErrorHandlerHandlesThrowables()
265292$ callableResolver =$ app ->getCallableResolver ();
266293$ logger =$ this ->getMockLogger ();
267294
268- $ mw =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
295+ $ middleware =new ErrorMiddleware ($ callableResolver ,$ this ->getResponseFactory (),false ,false ,false ,$ logger );
269296
270297$ app ->add (function ($ request ,$ handler ) {
271298throw new Error ('Oops.. ' );
272299 });
273300
274- $ mw ->setDefaultErrorHandler ((function (ServerRequestInterface $ request ,$ exception ) {
301+ $ middleware ->setDefaultErrorHandler ((function (ServerRequestInterface $ request ,$ exception ) {
275302$ response =$ this ->createResponse ();
276303$ response ->getBody ()->write ($ exception ->getMessage ());
277304return $ response ;
278305 })->bindTo ($ this ));
279306
280- $ app ->add ($ mw );
307+ $ app ->add ($ middleware );
281308
282309$ app ->get ('/foo ' ,function (ServerRequestInterface $ request ,ResponseInterface $ response ) {
283310$ response ->getBody ()->write ('... ' );