Skip to content

Commit 2e67236

Browse files
committed
fix: more coverage
1 parent a48bc8a commit 2e67236

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

system/HTTP/CURLRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,8 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
617617
}
618618

619619
// DNS Cache Timeout
620-
if (isset($config['dns_cache_timeout']) && is_numeric($config['dns_cache_timeout']) && $config['dns_cache_timeout'] > 0) {
621-
$curlOptions[CURLOPT_DNS_CACHE_TIMEOUT] = $config['dns_cache_timeout'];
620+
if (isset($config['dns_cache_timeout']) && is_numeric($config['dns_cache_timeout']) && $config['dns_cache_timeout'] >= -1) {
621+
$curlOptions[CURLOPT_DNS_CACHE_TIMEOUT] = (int) $config['dns_cache_timeout'];
622622
}
623623

624624
// Timeout

tests/system/HTTP/CURLRequestTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,8 @@ public function testForceResolveIPUnknown(): void
12151215

12161216
/**
12171217
* @return array<string, array<string, bool|int|string>>
1218+
*
1219+
* @see https://linux.die.net/man/3/curl_easy_setopt
12181220
*/
12191221
public static function provideDNSCacheTimeout(): iterable
12201222
{
@@ -1227,7 +1229,17 @@ public static function provideDNSCacheTimeout(): iterable
12271229
'valid timeout (numeric string)' => [
12281230
'input' => '180',
12291231
'expectedHasKey' => true,
1230-
'expectedValue' => '180',
1232+
'expectedValue' => 180,
1233+
],
1234+
'valid timeout (zero / disabled)' => [
1235+
'input' => 0,
1236+
'expectedHasKey' => true,
1237+
'expectedValue' => 0,
1238+
],
1239+
'valid timeout (forever)' => [
1240+
'input' => -1,
1241+
'expectedHasKey' => true,
1242+
'expectedValue' => -1,
12311243
],
12321244
'invalid timeout (null)' => [
12331245
'input' => null,
@@ -1237,11 +1249,7 @@ public static function provideDNSCacheTimeout(): iterable
12371249
'input' => 'is_wrong',
12381250
'expectedHasKey' => false,
12391251
],
1240-
'invalid timeout (zero)' => [
1241-
'input' => 0,
1242-
'expectedHasKey' => false,
1243-
],
1244-
'invalid timeout (negative number)' => [
1252+
'invalid timeout (negative number / below -1)' => [
12451253
'input' => -2,
12461254
'expectedHasKey' => false,
12471255
],

0 commit comments

Comments
 (0)