|
22 | 22 | use Config\CURLRequest as ConfigCURLRequest; |
23 | 23 | use CURLFile; |
24 | 24 | use PHPUnit\Framework\Attributes\BackupGlobals; |
| 25 | +use PHPUnit\Framework\Attributes\DataProvider; |
25 | 26 | use PHPUnit\Framework\Attributes\Group; |
26 | 27 |
|
27 | 28 | /** |
@@ -1212,40 +1213,52 @@ public function testForceResolveIPUnknown(): void |
1212 | 1213 | $this->assertSame(\CURL_IPRESOLVE_WHATEVER, $options[CURLOPT_IPRESOLVE]); |
1213 | 1214 | } |
1214 | 1215 |
|
1215 | | - public function testDNSCacheTimeoutEmptyOption(): void |
1216 | | - { |
1217 | | - $this->request->request('POST', '/post', [ |
1218 | | - 'dns_cache_timeout' => 0, |
1219 | | - ]); |
1220 | | - |
1221 | | - $options = $this->request->curl_options; |
1222 | | - |
1223 | | - $this->assertArrayNotHasKey(CURLOPT_DNS_CACHE_TIMEOUT, $options); |
1224 | | - } |
1225 | | - |
1226 | | - public function testDNSCacheTimeoutSetOption(): void |
| 1216 | + /** |
| 1217 | + * @return array<string, array<string, bool|int|string>> |
| 1218 | + */ |
| 1219 | + public static function provideDNSCacheTimeout(): iterable |
1227 | 1220 | { |
1228 | | - $timeout = 160; |
1229 | | - $this->request->request('POST', '/post', [ |
1230 | | - 'dns_cache_timeout' => $timeout, |
1231 | | - ]); |
1232 | | - |
1233 | | - $options = $this->request->curl_options; |
1234 | | - |
1235 | | - $this->assertArrayHasKey(CURLOPT_DNS_CACHE_TIMEOUT, $options); |
1236 | | - $this->assertSame($timeout, $options[CURLOPT_DNS_CACHE_TIMEOUT]); |
| 1221 | + yield from [ |
| 1222 | + 'valid timeout (integer)' => [ |
| 1223 | + 'input' => 160, |
| 1224 | + 'expectedHasKey' => true, |
| 1225 | + 'expectedValue' => 160, |
| 1226 | + ], |
| 1227 | + 'valid timeout (numeric string)' => [ |
| 1228 | + 'input' => '180', |
| 1229 | + 'expectedHasKey' => true, |
| 1230 | + 'expectedValue' => '180', |
| 1231 | + ], |
| 1232 | + 'invalid timeout (string)' => [ |
| 1233 | + 'input' => 'is_wrong', |
| 1234 | + 'expectedHasKey' => false, |
| 1235 | + ], |
| 1236 | + 'invalid timeout (zero)' => [ |
| 1237 | + 'input' => 0, |
| 1238 | + 'expectedHasKey' => false, |
| 1239 | + ], |
| 1240 | + 'invalid timeout (negative number)' => [ |
| 1241 | + 'input' => -2, |
| 1242 | + 'expectedHasKey' => false, |
| 1243 | + ], |
| 1244 | + ]; |
1237 | 1245 | } |
1238 | 1246 |
|
1239 | | - public function testDNSCacheTimeoutWrongSetOption(): void |
| 1247 | + #[DataProvider('provideDNSCacheTimeout')] |
| 1248 | + public function testDNSCacheTimeoutOption($input, bool $expectedHasKey, $expectedValue = null): void |
1240 | 1249 | { |
1241 | | - $timeout = 'is_wrong'; |
1242 | 1250 | $this->request->request('POST', '/post', [ |
1243 | | - 'dns_cache_timeout' => $timeout, |
| 1251 | + 'dns_cache_timeout' => $input, |
1244 | 1252 | ]); |
1245 | 1253 |
|
1246 | 1254 | $options = $this->request->curl_options; |
1247 | 1255 |
|
1248 | | - $this->assertArrayNotHasKey(CURLOPT_DNS_CACHE_TIMEOUT, $options); |
| 1256 | + if ($expectedHasKey) { |
| 1257 | + $this->assertArrayHasKey(CURLOPT_DNS_CACHE_TIMEOUT, $options); |
| 1258 | + $this->assertSame($expectedValue, $options[CURLOPT_DNS_CACHE_TIMEOUT]); |
| 1259 | + } else { |
| 1260 | + $this->assertArrayNotHasKey(CURLOPT_DNS_CACHE_TIMEOUT, $options); |
| 1261 | + } |
1249 | 1262 | } |
1250 | 1263 |
|
1251 | 1264 | public function testCookieOption(): void |
|
0 commit comments