Skip to content

Commit 6705f56

Browse files
Adding tests
1 parent 398d2d5 commit 6705f56

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/EventSubscriber/CorrelationIdSubscriberTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ public function setUp(): void
2929
parent::setUp();
3030
}
3131

32+
public function testOnKernelRequestConfigWithOtherHeader(): void
33+
{
34+
$request = new Request();
35+
$request->headers->set('X-Correlation-ID', self::CORRELATION_ID);
36+
37+
$requestEvent = new RequestEvent(
38+
$this->createMock(\Symfony\Component\HttpKernel\HttpKernelInterface::class),
39+
$request,
40+
null
41+
);
42+
43+
$subscriber = new CorrelationIdSubscriber([
44+
'request_header_name' => 'CID-IN',
45+
]);
46+
$subscriber->onKernelRequest($requestEvent);
47+
48+
$this->assertNotEmpty($request->attributes->get('CID-IN'));
49+
$this->assertSame(self::CORRELATION_ID, $request->attributes->get('CID-IN'));
50+
}
51+
3252
public function testOnKernelRequest(): void
3353
{
3454
$request = new Request();
@@ -64,6 +84,25 @@ public function testOnKernelResponse(): void
6484
$this->assertNotEmpty($response->headers->get('X-Correlation-ID'));
6585
}
6686

87+
public function testOnKernelResponseConfigWithOtherHeader(): void
88+
{
89+
$response = new Response();
90+
91+
$responseEvent = new ResponseEvent(
92+
$this->createMock(\Symfony\Component\HttpKernel\HttpKernelInterface::class),
93+
new Request(),
94+
1,
95+
$response
96+
);
97+
98+
$subscriber = new CorrelationIdSubscriber([
99+
'response_header_name' => 'CID-OUT',
100+
]);
101+
$subscriber->onKernelResponse($responseEvent);
102+
103+
$this->assertNotEmpty($response->headers->get('CID-OUT'));
104+
}
105+
67106
/**
68107
* @SuppressWarnings(PHPMD.StaticAccess)
69108
*/

0 commit comments

Comments
 (0)