2
2
3
3
namespace Lamoda \Metric \MetricBundle \Tests \Controller ;
4
4
5
+ use Exception ;
5
6
use Lamoda \Metric \Collector \MetricCollectorInterface ;
6
7
use Lamoda \Metric \Common \Metric ;
7
8
use Lamoda \Metric \Common \Source \IterableMetricSource ;
8
9
use Lamoda \Metric \MetricBundle \Controller \HttpFoundationResponder ;
9
10
use Lamoda \Metric \Responder \PsrResponder ;
10
11
use Lamoda \Metric \Responder \ResponseFactory \TelegrafJsonResponseFactory ;
11
12
use PHPUnit \Framework \TestCase ;
13
+ use Symfony \Component \HttpFoundation \Response ;
14
+ use Symfony \Component \HttpKernel \Exception \HttpException ;
12
15
13
16
/**
14
17
* @covers \Lamoda\Metric\MetricBundle\Controller\HttpFoundationResponder
15
18
*/
16
19
final class HttpFoundationResponderTest extends TestCase
17
20
{
18
- public function testControllerProducesJsonResult ()
21
+ public function testControllerProducesJsonResult (): void
19
22
{
20
23
$ m1 = new Metric ('m1 ' , 1.1 );
21
24
$ m2 = new Metric ('m2 ' , 2 );
@@ -41,4 +44,19 @@ public function testControllerProducesJsonResult()
41
44
$ this ->assertSame ('application/json ' , $ response ->headers ->get ('Content-Type ' ));
42
45
$ this ->assertJsonStringEqualsJsonString ($ expected , $ response ->getContent ());
43
46
}
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
+ }
44
62
}
0 commit comments