2121use Config \App ;
2222use Config \CURLRequest as ConfigCURLRequest ;
2323use CURLFile ;
24+ use CurlShareHandle ;
2425use PHPUnit \Framework \Attributes \BackupGlobals ;
2526use PHPUnit \Framework \Attributes \DataProvider ;
2627use 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 *
0 commit comments