@@ -143,11 +143,14 @@ public function testProcessWithMetricsDisabled(): void
143143 $ this ->assertSame ($ this ->response , $ result );
144144 }
145145
146- public function testProcessWithException (): void
146+ /**
147+ * @dataProvider exceptionCodeProvider
148+ */
149+ public function testProcessWithException (int $ exceptionCode , int $ expectedStatusCode ): void
147150 {
148151 $ path = '/api/error ' ;
149152 $ method = 'POST ' ;
150- $ exception = new RuntimeException ('Test exception ' );
153+ $ exception = new RuntimeException ('Test exception ' , $ exceptionCode );
151154
152155 $ this ->uri ->method ('getPath ' )->willReturn ($ path );
153156 $ this ->request ->method ('getMethod ' )->willReturn ($ method );
@@ -169,7 +172,7 @@ public function testProcessWithException(): void
169172 HttpAttributes::HTTP_ROUTE => $ path ,
170173 HttpAttributes::HTTP_REQUEST_METHOD => $ method ,
171174 ErrorAttributes::ERROR_TYPE => RuntimeException::class,
172- HttpAttributes::HTTP_RESPONSE_STATUS_CODE => 500 ,
175+ HttpAttributes::HTTP_RESPONSE_STATUS_CODE => $ expectedStatusCode ,
173176 ]
174177 );
175178
@@ -185,6 +188,24 @@ public function testProcessWithException(): void
185188 $ middleware ->process ($ this ->request , $ handler );
186189 }
187190
191+ public static function exceptionCodeProvider (): array
192+ {
193+ return [
194+ 'Default exception code ' => [
195+ 'exceptionCode ' => 0 ,
196+ 'expectedStatusCode ' => 500 ,
197+ ],
198+ 'Http exception code ' => [
199+ 'exceptionCode ' => 422 ,
200+ 'expectedStatusCode ' => 422 ,
201+ ],
202+ 'Custom exception code ' => [
203+ 'exceptionCode ' => 1000 ,
204+ 'expectedStatusCode ' => 500 ,
205+ ],
206+ ];
207+ }
208+
188209 private function configureRequestMock (string $ method , string $ path ): void
189210 {
190211 $ this ->uri ->method ('getPath ' )->willReturn ($ path );
0 commit comments