Skip to content

Commit

Permalink
Merge pull request #25 from unwelt/fix/compability_with_http-kernel_6.x
Browse files Browse the repository at this point in the history
Added support Symfony HttpKernel 6.x
  • Loading branch information
unwelt authored Nov 13, 2024
2 parents 23a7077 + bb67abd commit 0451d7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/MetricBundle/Controller/HttpFoundationResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function createResponse(): Response
$response->getHeaders()
);
} catch (\Exception $exception) {
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, null, $exception);
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, '', $exception);
}

$symfonyResponse->setPrivate();
Expand Down
20 changes: 19 additions & 1 deletion tests/MetricBundle/Controller/HttpFoundationResponderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

namespace Lamoda\Metric\MetricBundle\Tests\Controller;

use Exception;
use Lamoda\Metric\Collector\MetricCollectorInterface;
use Lamoda\Metric\Common\Metric;
use Lamoda\Metric\Common\Source\IterableMetricSource;
use Lamoda\Metric\MetricBundle\Controller\HttpFoundationResponder;
use Lamoda\Metric\Responder\PsrResponder;
use Lamoda\Metric\Responder\ResponseFactory\TelegrafJsonResponseFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;

/**
* @covers \Lamoda\Metric\MetricBundle\Controller\HttpFoundationResponder
*/
final class HttpFoundationResponderTest extends TestCase
{
public function testControllerProducesJsonResult()
public function testControllerProducesJsonResult(): void
{
$m1 = new Metric('m1', 1.1);
$m2 = new Metric('m2', 2);
Expand All @@ -41,4 +44,19 @@ public function testControllerProducesJsonResult()
$this->assertSame('application/json', $response->headers->get('Content-Type'));
$this->assertJsonStringEqualsJsonString($expected, $response->getContent());
}

public function testControllerCorrectHandleException(): void
{
$exception = new Exception('Test exception');
$expectedExceptionObject = new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, '', $exception);

$collector = $this->createMock(MetricCollectorInterface::class);
$collector->method('collect')->willThrowException($exception);

$controller = new HttpFoundationResponder(new PsrResponder($collector, new TelegrafJsonResponseFactory()));

$this->expectExceptionObject($expectedExceptionObject);

$controller->createResponse();
}
}

0 comments on commit 0451d7e

Please sign in to comment.