Skip to content

Commit 251d092

Browse files
committed
refactor: more applied suggest recommendation
1 parent a8a548c commit 251d092

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

app/Config/CURLRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class CURLRequest extends BaseConfig
88
{
99
/**
1010
* --------------------------------------------------------------------------
11-
* CURLRequest Share Connection
11+
* CURLRequest Share Connection Options
1212
* --------------------------------------------------------------------------
1313
*
14-
* Whether share connection between requests.
14+
* Share connection options between requests.
1515
*
1616
* @var list<int>
1717
*

system/HTTP/CURLRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class CURLRequest extends OutgoingRequest
103103
private readonly bool $shareOptions;
104104

105105
/**
106-
* Whether share connection between requests.
106+
* The share connection instance.
107107
*/
108108
protected ?CurlShareHandle $shareConnection = null;
109109

tests/system/HTTP/CURLRequestShareOptionsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
#[Group('Others')]
2929
final class CURLRequestShareOptionsTest extends CURLRequestTest
3030
{
31-
protected function getRequest(array $options = [], bool $emptyShareConnection = false): MockCURLRequest
31+
protected function getRequest(array $options = [], ?array $shareConnectionOptions = null): MockCURLRequest
3232
{
3333
$uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI();
3434
$app = new App();
3535

3636
$config = new ConfigCURLRequest();
3737
$config->shareOptions = true;
3838

39-
if ($emptyShareConnection) {
40-
$config->shareConnectionOptions = [];
39+
if ($shareConnectionOptions !== null) {
40+
$config->shareConnectionOptions = $shareConnectionOptions;
4141
}
4242

4343
Factories::injectMock('config', 'CURLRequest', $config);

tests/system/HTTP/CURLRequestTest.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Config\App;
2222
use Config\CURLRequest as ConfigCURLRequest;
2323
use CURLFile;
24+
use CurlShareHandle;
2425
use PHPUnit\Framework\Attributes\BackupGlobals;
2526
use PHPUnit\Framework\Attributes\DataProvider;
2627
use PHPUnit\Framework\Attributes\Group;
@@ -45,17 +46,18 @@ protected function setUp(): void
4546

4647
/**
4748
* @param array<string, mixed> $options
49+
* @param array<int, int>|null $shareConnectionOptions
4850
*/
49-
protected function getRequest(array $options = [], bool $emptyShareConnection = false): MockCURLRequest
51+
protected function getRequest(array $options = [], ?array $shareConnectionOptions = null): MockCURLRequest
5052
{
5153
$uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI();
5254
$app = new App();
5355

5456
$config = new ConfigCURLRequest();
5557
$config->shareOptions = false;
5658

57-
if ($emptyShareConnection) {
58-
$config->shareConnectionOptions = [];
59+
if ($shareConnectionOptions !== null) {
60+
$config->shareConnectionOptions = $shareConnectionOptions;
5961
}
6062

6163
Factories::injectMock('config', 'CURLRequest', $config);
@@ -1247,18 +1249,35 @@ public function testShareConnectionDefault(): void
12471249
$options = $this->request->curl_options;
12481250

12491251
$this->assertArrayHasKey(CURLOPT_SHARE, $options);
1252+
$this->assertInstanceOf(CurlShareHandle::class, $options[CURLOPT_SHARE]);
12501253
}
12511254

12521255
public function testShareConnectionEmpty(): void
12531256
{
1254-
$request = $this->getRequest(emptyShareConnection: true);
1257+
$request = $this->getRequest(shareConnectionOptions: []);
12551258
$request->request('GET', 'http://example.com');
12561259

12571260
$options = $request->curl_options;
12581261

12591262
$this->assertArrayNotHasKey(CURLOPT_SHARE, $options);
12601263
}
12611264

1265+
public function testShareConnectionDuplicate(): void
1266+
{
1267+
$request = $this->getRequest(shareConnectionOptions: [
1268+
CURL_LOCK_DATA_CONNECT,
1269+
CURL_LOCK_DATA_DNS,
1270+
CURL_LOCK_DATA_CONNECT,
1271+
CURL_LOCK_DATA_DNS,
1272+
]);
1273+
$request->request('GET', 'http://example.com');
1274+
1275+
$options = $request->curl_options;
1276+
1277+
$this->assertArrayHasKey(CURLOPT_SHARE, $options);
1278+
$this->assertInstanceOf(CurlShareHandle::class, $options[CURLOPT_SHARE]);
1279+
}
1280+
12621281
/**
12631282
* @return iterable<string, array{input: int|string|null, expectedHasKey: bool, expectedValue?: int}>
12641283
*

user_guide_src/source/libraries/curlrequest/039.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class CURLRequest extends BaseConfig
88
{
99
/**
1010
* --------------------------------------------------------------------------
11-
* CURLRequest Share Connection
11+
* CURLRequest Share Connection Options
1212
* --------------------------------------------------------------------------
1313
*
14-
* Whether share connection between requests.
14+
* Share connection options between requests.
1515
*
1616
* @var list<int>
1717
*

user_guide_src/source/libraries/curlrequest/040.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class CURLRequest extends BaseConfig
88
{
99
/**
1010
* --------------------------------------------------------------------------
11-
* CURLRequest Share Connection
11+
* CURLRequest Share Connection Options
1212
* --------------------------------------------------------------------------
1313
*
14-
* Whether share connection between requests.
14+
* Share connection options between requests.
1515
*
1616
* @var list<int>
1717
*

0 commit comments

Comments
 (0)