Skip to content
Closed
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
16 changes: 16 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ public function sendAsyncRequest(RequestInterface $request)
return $promise;
}

/**
* @param int $option
*
* @throws \RuntimeException On invalid resource
*
* @return mixed
*/
public function getCurlInfo($option = 0)
{
if (false === is_resource($this->handle)) {
throw new \RuntimeException('Cannot retrieve info: resource missing');
}

return $option ? curl_getinfo($this->handle, $option) : curl_getinfo($this->handle);
}

/**
* Generates cURL options.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,31 @@ public function testFactoryDiscovery()

static::assertInstanceOf(Client::class, $client);
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Cannot retrieve info: resource missing
*/
public function testEmptyResource()
{
$client = new Client();

$client->getCurlInfo();
}

public function testFailedRequest()
{
$client = new Client();

$handle = new \ReflectionProperty(Client::class, 'handle');
$handle->setAccessible(true);
$handle->setValue($client, curl_init());
$optionInfo = $client->getCurlInfo(CURLINFO_HTTP_CODE);
static::assertTrue(is_int($optionInfo));
static::assertEquals(0, $optionInfo);
$allInfo = $client->getCurlInfo();
static::assertTrue(is_array($allInfo));
static::assertEquals(0, $allInfo['request_size']);
static::assertEquals(0, $allInfo['http_code']);
}
}