Skip to content

Commit 0451d7e

Browse files
authored
Merge pull request #25 from unwelt/fix/compability_with_http-kernel_6.x
Added support Symfony HttpKernel 6.x
2 parents 23a7077 + bb67abd commit 0451d7e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/MetricBundle/Controller/HttpFoundationResponder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function createResponse(): Response
3939
$response->getHeaders()
4040
);
4141
} catch (\Exception $exception) {
42-
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, null, $exception);
42+
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, '', $exception);
4343
}
4444

4545
$symfonyResponse->setPrivate();

tests/MetricBundle/Controller/HttpFoundationResponderTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
namespace Lamoda\Metric\MetricBundle\Tests\Controller;
44

5+
use Exception;
56
use Lamoda\Metric\Collector\MetricCollectorInterface;
67
use Lamoda\Metric\Common\Metric;
78
use Lamoda\Metric\Common\Source\IterableMetricSource;
89
use Lamoda\Metric\MetricBundle\Controller\HttpFoundationResponder;
910
use Lamoda\Metric\Responder\PsrResponder;
1011
use Lamoda\Metric\Responder\ResponseFactory\TelegrafJsonResponseFactory;
1112
use 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
*/
1619
final 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

Comments
 (0)