|
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,6 +1213,76 @@ public function testForceResolveIPUnknown(): void
|
1212 | 1213 | $this->assertSame(\CURL_IPRESOLVE_WHATEVER, $options[CURLOPT_IPRESOLVE]);
|
1213 | 1214 | }
|
1214 | 1215 |
|
| 1216 | + /** |
| 1217 | + * @return iterable<string, array{input: int|string|null, expectedHasKey: bool, expectedValue?: int}> |
| 1218 | + * |
| 1219 | + * @see https://curl.se/libcurl/c/CURLOPT_DNS_CACHE_TIMEOUT.html |
| 1220 | + */ |
| 1221 | + public static function provideDNSCacheTimeout(): iterable |
| 1222 | + { |
| 1223 | + yield from [ |
| 1224 | + 'valid timeout (integer)' => [ |
| 1225 | + 'input' => 160, |
| 1226 | + 'expectedHasKey' => true, |
| 1227 | + 'expectedValue' => 160, |
| 1228 | + ], |
| 1229 | + 'valid timeout (numeric string)' => [ |
| 1230 | + 'input' => '180', |
| 1231 | + 'expectedHasKey' => true, |
| 1232 | + 'expectedValue' => 180, |
| 1233 | + ], |
| 1234 | + 'valid timeout (zero / disabled)' => [ |
| 1235 | + 'input' => 0, |
| 1236 | + 'expectedHasKey' => true, |
| 1237 | + 'expectedValue' => 0, |
| 1238 | + ], |
| 1239 | + 'valid timeout (zero / disabled using string)' => [ |
| 1240 | + 'input' => '0', |
| 1241 | + 'expectedHasKey' => true, |
| 1242 | + 'expectedValue' => 0, |
| 1243 | + ], |
| 1244 | + 'valid timeout (forever)' => [ |
| 1245 | + 'input' => -1, |
| 1246 | + 'expectedHasKey' => true, |
| 1247 | + 'expectedValue' => -1, |
| 1248 | + ], |
| 1249 | + 'valid timeout (forever using string)' => [ |
| 1250 | + 'input' => '-1', |
| 1251 | + 'expectedHasKey' => true, |
| 1252 | + 'expectedValue' => -1, |
| 1253 | + ], |
| 1254 | + 'invalid timeout (null)' => [ |
| 1255 | + 'input' => null, |
| 1256 | + 'expectedHasKey' => false, |
| 1257 | + ], |
| 1258 | + 'invalid timeout (string)' => [ |
| 1259 | + 'input' => 'is_wrong', |
| 1260 | + 'expectedHasKey' => false, |
| 1261 | + ], |
| 1262 | + 'invalid timeout (negative number / below -1)' => [ |
| 1263 | + 'input' => -2, |
| 1264 | + 'expectedHasKey' => false, |
| 1265 | + ], |
| 1266 | + ]; |
| 1267 | + } |
| 1268 | + |
| 1269 | + #[DataProvider('provideDNSCacheTimeout')] |
| 1270 | + public function testDNSCacheTimeoutOption(int|string|null $input, bool $expectedHasKey, ?int $expectedValue = null): void |
| 1271 | + { |
| 1272 | + $this->request->request('POST', '/post', [ |
| 1273 | + 'dns_cache_timeout' => $input, |
| 1274 | + ]); |
| 1275 | + |
| 1276 | + $options = $this->request->curl_options; |
| 1277 | + |
| 1278 | + if ($expectedHasKey) { |
| 1279 | + $this->assertArrayHasKey(CURLOPT_DNS_CACHE_TIMEOUT, $options); |
| 1280 | + $this->assertSame($expectedValue, $options[CURLOPT_DNS_CACHE_TIMEOUT]); |
| 1281 | + } else { |
| 1282 | + $this->assertArrayNotHasKey(CURLOPT_DNS_CACHE_TIMEOUT, $options); |
| 1283 | + } |
| 1284 | + } |
| 1285 | + |
1215 | 1286 | public function testCookieOption(): void
|
1216 | 1287 | {
|
1217 | 1288 | $holder = SUPPORTPATH . 'HTTP/Files/CookiesHolder.txt';
|
|
0 commit comments