22
33namespace Lamoda \Metric \MetricBundle \Tests \Controller ;
44
5+ use Exception ;
56use Lamoda \Metric \Collector \MetricCollectorInterface ;
67use Lamoda \Metric \Common \Metric ;
78use Lamoda \Metric \Common \Source \IterableMetricSource ;
89use Lamoda \Metric \MetricBundle \Controller \HttpFoundationResponder ;
910use Lamoda \Metric \Responder \PsrResponder ;
1011use Lamoda \Metric \Responder \ResponseFactory \TelegrafJsonResponseFactory ;
1112use PHPUnit \Framework \TestCase ;
13+ use Symfony \Component \HttpFoundation \Response ;
14+ use Symfony \Component \HttpKernel \Exception \HttpException ;
1215
1316/**
1417 * @covers \Lamoda\Metric\MetricBundle\Controller\HttpFoundationResponder
1518 */
1619final class HttpFoundationResponderTest extends TestCase
1720{
18- public function testControllerProducesJsonResult ()
21+ public function testControllerProducesJsonResult (): void
1922 {
2023 $ m1 = new Metric ('m1 ' , 1.1 );
2124 $ m2 = new Metric ('m2 ' , 2 );
@@ -41,4 +44,19 @@ public function testControllerProducesJsonResult()
4144 $ this ->assertSame ('application/json ' , $ response ->headers ->get ('Content-Type ' ));
4245 $ this ->assertJsonStringEqualsJsonString ($ expected , $ response ->getContent ());
4346 }
47+
48+ public function testControllerCorrectHandleException (): void
49+ {
50+ $ exception = new Exception ('Test exception ' );
51+ $ expectedExceptionObject = new HttpException (Response::HTTP_INTERNAL_SERVER_ERROR , '' , $ exception );
52+
53+ $ collector = $ this ->createMock (MetricCollectorInterface::class);
54+ $ collector ->method ('collect ' )->willThrowException ($ exception );
55+
56+ $ controller = new HttpFoundationResponder (new PsrResponder ($ collector , new TelegrafJsonResponseFactory ()));
57+
58+ $ this ->expectExceptionObject ($ expectedExceptionObject );
59+
60+ $ controller ->createResponse ();
61+ }
4462}
0 commit comments