File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -52,4 +52,28 @@ public function testOnDispatchErrorReturnsAnApiProblemResponseBasedOnCurrentEven
5252 $ this ->assertEquals (400 , $ problem ->status );
5353 $ this ->assertSame ($ event ->getParam ('exception ' ), $ problem ->detail );
5454 }
55+
56+ /**
57+ * @requires PHP 7.0
58+ */
59+ public function testOnDispatchErrorReturnsAnApiProblemResponseBasedOnCurrentEventThrowable ()
60+ {
61+ $ request = new Request ();
62+ $ request ->getHeaders ()->addHeaderLine ('Accept ' , 'application/json ' );
63+
64+ $ event = new MvcEvent ();
65+ $ event ->setError (Application::ERROR_EXCEPTION );
66+ $ event ->setParam ('exception ' , new \TypeError ('triggering throwable ' , 400 ));
67+ $ event ->setRequest ($ request );
68+ $ return = $ this ->listener ->onDispatchError ($ event );
69+
70+ $ this ->assertTrue ($ event ->propagationIsStopped ());
71+ $ this ->assertInstanceOf ('ZF\ApiProblem\ApiProblemResponse ' , $ return );
72+ $ response = $ event ->getResponse ();
73+ $ this ->assertSame ($ return , $ response );
74+ $ problem = $ response ->getApiProblem ();
75+ $ this ->assertInstanceOf ('ZF\ApiProblem\ApiProblem ' , $ problem );
76+ $ this ->assertEquals (400 , $ problem ->status );
77+ $ this ->assertSame ($ event ->getParam ('exception ' ), $ problem ->detail );
78+ }
5579}
You can’t perform that action at this time.
0 commit comments