Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/VCR/LibraryHooks/CurlHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,18 @@ public static function curlExec(\CurlHandle $curlHandle)
*
* @see http://www.php.net/manual/en/function.curl-multi-add-handle.php
*/
public static function curlMultiAddHandle(\CurlMultiHandle $multiHandle, \CurlHandle $curlHandle): void
public static function curlMultiAddHandle(\CurlMultiHandle $multiHandle, \CurlHandle $curlHandle): int
{
if (!isset(self::$multiHandles[(int) $multiHandle])) {
self::$multiHandles[(int) $multiHandle] = [];
}

self::$multiHandles[(int) $multiHandle][(int) $curlHandle] = $curlHandle;

// Mirror the real curl_multi_add_handle() return contract. Callers such as
// Guzzle >= 7.13 strictly check `\CURLM_OK !== $result` and throw otherwise;
// returning void (null) here made that check fail with "No error (0)".
return \CURLM_OK;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/LibraryHooks/CurlHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,31 @@ function (Request $request) use ($testClass, &$callCount) {
);
}

public function testCurlMultiAddHandleReturnsCurlmOk(): void
{
$this->curlHook->enable(
fn (Request $request): Response => new Response('200')
);

$curlHandle = curl_init('http://example.com');
Assertion::notSame($curlHandle, false);

$curlMultiHandle = curl_multi_init();
Assertion::notSame($curlMultiHandle, false);

// Real curl_multi_add_handle() returns CURLM_OK (0) on success. Guzzle >= 7.13
// strictly checks `\CURLM_OK !== $result` and throws when it is not returned,
// so the intercepted call must mirror that contract rather than return void.
$result = curl_multi_add_handle($curlMultiHandle, $curlHandle);

curl_multi_remove_handle($curlMultiHandle, $curlHandle);
curl_multi_close($curlMultiHandle);

$this->curlHook->disable();

$this->assertSame(\CURLM_OK, $result, 'Intercepted curl_multi_add_handle should return CURLM_OK.');
}

/**
* @requires PHP 5.5.0
*/
Expand Down
Loading