@@ -275,4 +275,39 @@ public function testMiddlewareWithNothingPipedReachesFinalHandlerException()
275275 $ return = $ listener ->onDispatch ($ event );
276276 $ this ->assertEquals ('FAILED ' , $ return );
277277 }
278+
279+ public function testNullMiddlewareThrowsInvalidArgument ()
280+ {
281+ $ response = new Response ();
282+ $ routeMatch = $ this ->prophesize (RouteMatch::class);
283+ $ routeMatch ->getParams ()->willReturn ([]);
284+ $ routeMatch ->getParam ('middleware ' , false )->willReturn ([null ]);
285+
286+ $ eventManager = new EventManager ();
287+
288+ $ serviceManager = $ this ->prophesize (ContainerInterface::class);
289+ $ application = $ this ->prophesize (Application::class);
290+ $ application ->getEventManager ()->willReturn ($ eventManager );
291+ $ application ->getServiceManager ()->will (function () use ($ serviceManager ) {
292+ return $ serviceManager ->reveal ();
293+ });
294+ $ application ->getResponse ()->willReturn ($ response );
295+
296+ $ event = new MvcEvent ();
297+ $ event ->setRequest (new Request ());
298+ $ event ->setResponse ($ response );
299+ $ event ->setApplication ($ application ->reveal ());
300+ $ event ->setRouteMatch ($ routeMatch ->reveal ());
301+
302+ $ event ->getApplication ()->getEventManager ()->attach (MvcEvent::EVENT_DISPATCH_ERROR , function ($ e ) {
303+ $ this ->assertEquals (Application::ERROR_EXCEPTION , $ e ->getError ());
304+ $ this ->assertInstanceOf (ReachedFinalHandlerException::class, $ e ->getParam ('exception ' ));
305+ return 'FAILED ' ;
306+ });
307+
308+ $ listener = new MiddlewareListener ();
309+
310+ $ this ->setExpectedException (\InvalidArgumentException::class);
311+ $ listener ->onDispatch ($ event );
312+ }
278313}
0 commit comments