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.');
}
}

2 comments on commit cd87e6a

@nategood
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to open this up as a pull request? We'll get it merged in.

@quixand
Copy link
Owner

@quixand quixand commented on cd87e6a Dec 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK but I'm not sure the test class has the most appropriate name 'curlOutputBugTest'. It was done in bit of a rush. You don't seem to have dedicated test classes and this is testing a specific method of the Request class so perhaps this could be renamed TestRequest? Also those two tests are doing the same thing so one needs to be removed, that was more so you could copy the one you preferred, up to you if you prefer the annotation pattern of phpunit or the try catch? The test method names don't describe the current behavior but rather the unexpected error output I was seeing originally. Let me know which test patten you would prefer and I'll get this all cleaned up

Please sign in to comment.