Skip to content

Commit b9eb479

Browse files
committed
test and static-analysis fix
1 parent 4c132bc commit b9eb479

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎src/App/src/Handler/PostCreateContactHandler.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
class PostCreateContactHandler implements RequestHandlerInterface
2222
{
23+
/**
24+
* @param array{check_proxy_headers: bool, trusted_proxies: array<non-empty-string>, attribute_name: non-empty-string, headers_to_inspect: array<non-empty-string>} $ipAddressConfig
25+
*/
2326
#[Inject(
2427
TemplateRendererInterface::class,
2528
UrlHelper::class,

‎test/Unit/App/Handler/PostCreateContactHandlerTest.php‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@
2626

2727
class PostCreateContactHandlerTest extends TestCase
2828
{
29+
/**
30+
* @return array{
31+
* check_proxy_headers: bool,
32+
* trusted_proxies: array<non-empty-string>,
33+
* attribute_name: non-empty-string,
34+
* headers_to_inspect: array<non-empty-string>,
35+
* }
36+
*/
37+
private function ipAddressConfig(): array
38+
{
39+
return [
40+
'check_proxy_headers' => false,
41+
'trusted_proxies' => [],
42+
'attribute_name' => 'ip_address',
43+
'headers_to_inspect' => [],
44+
];
45+
}
46+
2947
/**
3048
* @return array<string, string>
3149
*/
@@ -74,7 +92,12 @@ public function testValidSubmissionRedirectsOnSuccess(): void
7492
->with('app::create-contact-form', [], ['contact' => 'sent'], 'contact-form')
7593
->willReturn('/contact/?contact=sent#contact-form');
7694

77-
$handler = new PostCreateContactHandler($template, $urlHelper, $this->service(new MailResult(true)));
95+
$handler = new PostCreateContactHandler(
96+
$template,
97+
$urlHelper,
98+
$this->service(new MailResult(true)),
99+
$this->ipAddressConfig()
100+
);
78101
$response = $handler->handle($request);
79102

80103
$this->assertInstanceOf(RedirectResponse::class, $response);
@@ -113,7 +136,8 @@ public function testMissingRequiredFieldsRerendersWithErrors(): void
113136
$handler = new PostCreateContactHandler(
114137
$template,
115138
$this->createStub(UrlHelper::class),
116-
$this->service(new MailResult(true))
139+
$this->service(new MailResult(true)),
140+
$this->ipAddressConfig()
117141
);
118142
$response = $handler->handle($request);
119143

@@ -150,7 +174,8 @@ public function testRerenderKeepsAnyExtraQueryParamsAsDynamicHiddenFields(): voi
150174
$handler = new PostCreateContactHandler(
151175
$template,
152176
$this->createStub(UrlHelper::class),
153-
$this->service(new MailResult(true))
177+
$this->service(new MailResult(true)),
178+
$this->ipAddressConfig()
154179
);
155180
$handler->handle($request);
156181
}
@@ -179,7 +204,8 @@ public function testMailTransportFailureRerendersWithMailFailedFlag(): void
179204
$handler = new PostCreateContactHandler(
180205
$template,
181206
$this->createStub(UrlHelper::class),
182-
$this->service(new RuntimeException('SMTP connection refused'))
207+
$this->service(new RuntimeException('SMTP connection refused')),
208+
$this->ipAddressConfig()
183209
);
184210
$response = $handler->handle($request);
185211

@@ -232,7 +258,12 @@ public function testFailedTurnstileRerendersWithCaptchaErrorAndSendsNothing(): v
232258
)
233259
->willReturn('<html></html>');
234260

235-
$handler = new PostCreateContactHandler($template, $this->createStub(UrlHelper::class), $contactService);
261+
$handler = new PostCreateContactHandler(
262+
$template,
263+
$this->createStub(UrlHelper::class),
264+
$contactService,
265+
$this->ipAddressConfig()
266+
);
236267
$response = $handler->handle($request);
237268

238269
$this->assertInstanceOf(HtmlResponse::class, $response);
@@ -272,7 +303,8 @@ public function testValidSubmissionSendsTheIpAddressFromTheRequestAttribute(): v
272303
$response = (new PostCreateContactHandler(
273304
$this->createStub(TemplateRendererInterface::class),
274305
$urlHelper,
275-
$contactService
306+
$contactService,
307+
$this->ipAddressConfig()
276308
))->handle($request);
277309

278310
$this->assertInstanceOf(RedirectResponse::class, $response);

0 commit comments

Comments
 (0)