Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Mar 28, 2024
1 parent 398d2d5 commit 6705f56
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/EventSubscriber/CorrelationIdSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ public function setUp(): void
parent::setUp();
}

public function testOnKernelRequestConfigWithOtherHeader(): void
{
$request = new Request();
$request->headers->set('X-Correlation-ID', self::CORRELATION_ID);

$requestEvent = new RequestEvent(
$this->createMock(\Symfony\Component\HttpKernel\HttpKernelInterface::class),
$request,
null
);

$subscriber = new CorrelationIdSubscriber([
'request_header_name' => 'CID-IN',
]);
$subscriber->onKernelRequest($requestEvent);

$this->assertNotEmpty($request->attributes->get('CID-IN'));
$this->assertSame(self::CORRELATION_ID, $request->attributes->get('CID-IN'));
}

public function testOnKernelRequest(): void
{
$request = new Request();
Expand Down Expand Up @@ -64,6 +84,25 @@ public function testOnKernelResponse(): void
$this->assertNotEmpty($response->headers->get('X-Correlation-ID'));
}

public function testOnKernelResponseConfigWithOtherHeader(): void
{
$response = new Response();

$responseEvent = new ResponseEvent(
$this->createMock(\Symfony\Component\HttpKernel\HttpKernelInterface::class),
new Request(),
1,
$response
);

$subscriber = new CorrelationIdSubscriber([
'response_header_name' => 'CID-OUT',
]);
$subscriber->onKernelResponse($responseEvent);

$this->assertNotEmpty($response->headers->get('CID-OUT'));
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
Expand Down

0 comments on commit 6705f56

Please sign in to comment.