|
26 | 26 |
|
27 | 27 | class PostCreateContactHandlerTest extends TestCase |
28 | 28 | { |
| 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 | + |
29 | 47 | /** |
30 | 48 | * @return array<string, string> |
31 | 49 | */ |
@@ -74,7 +92,12 @@ public function testValidSubmissionRedirectsOnSuccess(): void |
74 | 92 | ->with('app::create-contact-form', [], ['contact' => 'sent'], 'contact-form') |
75 | 93 | ->willReturn('/contact/?contact=sent#contact-form'); |
76 | 94 |
|
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 | + ); |
78 | 101 | $response = $handler->handle($request); |
79 | 102 |
|
80 | 103 | $this->assertInstanceOf(RedirectResponse::class, $response); |
@@ -113,7 +136,8 @@ public function testMissingRequiredFieldsRerendersWithErrors(): void |
113 | 136 | $handler = new PostCreateContactHandler( |
114 | 137 | $template, |
115 | 138 | $this->createStub(UrlHelper::class), |
116 | | - $this->service(new MailResult(true)) |
| 139 | + $this->service(new MailResult(true)), |
| 140 | + $this->ipAddressConfig() |
117 | 141 | ); |
118 | 142 | $response = $handler->handle($request); |
119 | 143 |
|
@@ -150,7 +174,8 @@ public function testRerenderKeepsAnyExtraQueryParamsAsDynamicHiddenFields(): voi |
150 | 174 | $handler = new PostCreateContactHandler( |
151 | 175 | $template, |
152 | 176 | $this->createStub(UrlHelper::class), |
153 | | - $this->service(new MailResult(true)) |
| 177 | + $this->service(new MailResult(true)), |
| 178 | + $this->ipAddressConfig() |
154 | 179 | ); |
155 | 180 | $handler->handle($request); |
156 | 181 | } |
@@ -179,7 +204,8 @@ public function testMailTransportFailureRerendersWithMailFailedFlag(): void |
179 | 204 | $handler = new PostCreateContactHandler( |
180 | 205 | $template, |
181 | 206 | $this->createStub(UrlHelper::class), |
182 | | - $this->service(new RuntimeException('SMTP connection refused')) |
| 207 | + $this->service(new RuntimeException('SMTP connection refused')), |
| 208 | + $this->ipAddressConfig() |
183 | 209 | ); |
184 | 210 | $response = $handler->handle($request); |
185 | 211 |
|
@@ -232,7 +258,12 @@ public function testFailedTurnstileRerendersWithCaptchaErrorAndSendsNothing(): v |
232 | 258 | ) |
233 | 259 | ->willReturn('<html></html>'); |
234 | 260 |
|
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 | + ); |
236 | 267 | $response = $handler->handle($request); |
237 | 268 |
|
238 | 269 | $this->assertInstanceOf(HtmlResponse::class, $response); |
@@ -272,7 +303,8 @@ public function testValidSubmissionSendsTheIpAddressFromTheRequestAttribute(): v |
272 | 303 | $response = (new PostCreateContactHandler( |
273 | 304 | $this->createStub(TemplateRendererInterface::class), |
274 | 305 | $urlHelper, |
275 | | - $contactService |
| 306 | + $contactService, |
| 307 | + $this->ipAddressConfig() |
276 | 308 | ))->handle($request); |
277 | 309 |
|
278 | 310 | $this->assertInstanceOf(RedirectResponse::class, $response); |
|
0 commit comments