Skip to content

Commit

Permalink
removed call to error_log and added detail exception output from curl…
Browse files Browse the repository at this point in the history
… execute to capturing exception
  • Loading branch information
nick.fox committed Nov 22, 2013
1 parent 3d0eb21 commit cd87e6a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Httpful/Request.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ public function send()
$result = curl_exec($this->_ch);

if ($result === false) {
$this->_error(curl_error($this->_ch));
if ($curlErrorNumber = curl_errno($this->_ch)) {
$curlErrorString = curl_error($this->_ch);
throw new ConnectionErrorException('Unable to connect: '.$curlErrorNumber.' '.$curlErrorString);
}

throw new ConnectionErrorException('Unable to connect.');
}

Expand Down
37 changes: 37 additions & 0 deletions tests/Httpful/curlOutputBugTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Port over the original tests into a more traditional PHPUnit
* format. Still need to hook into a lightweight HTTP server to
* better test some things (e.g. obscure cURL settings). I've moved
* the old tests and node.js server to the tests/.legacy directory.
* @author nick fox <quixand gmail com>
*/
namespace Httpful\Test;

class curlOutputBugTest extends \PHPUnit_Framework_TestCase
{

/**
* @author Nick Fox
* @expectedException Httpful\Exception\ConnectionErrorException
* @expectedExceptionMessage Unable to connect
*/
public function testInvalidURLGeneratesUnexpectedOutput()
{
\Httpful\Request::get('unavailable.url')->send();
}

/**
* @author Nick Fox
*/
public function testInvalidURLGeneratesUnexpectedOutput_catchException()
{
try {
$output = \Httpful\Request::get('unavailable.url')->send();
} catch (\Httpful\Exception\ConnectionErrorException $expected) {
$this->assertEquals('Unable to connect: 6 Couldn\'t resolve host \'unavailable.url\'', $expected->getMessage());
return;
}
$this->fail('An expected exception has not been raised.');
}
}

0 comments on commit cd87e6a

Please sign in to comment.