1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-03-14 19:29:49 +01:00

Fixing an issue with the history plugin

This commit is contained in:
Michael Dowling 2014-08-03 16:46:03 -07:00
parent e49ad58038
commit f221563b4e
3 changed files with 23 additions and 1 deletions

View File

@ -1,6 +1,12 @@
CHANGELOG
=========
Next Version
------------
* Fixed an error in the HistoryPlugin that caused the same request and response
to be logged multiple times when an HTTP protocol error occurs.
4.1.6 (2014-08-03)
------------------

View File

@ -56,7 +56,11 @@ class History implements SubscriberInterface, \IteratorAggregate, \Countable
public function onError(ErrorEvent $event)
{
$this->add($event->getRequest(), $event->getResponse());
// Only track when no response is present, meaning this didn't ever
// emit a complete event
if (!$event->getResponse()) {
$this->add($event->getRequest());
}
}
/**

View File

@ -28,6 +28,18 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
$ev = new ErrorEvent($t, $e);
$h = new History(2);
$h->onError($ev);
// Only tracks when no response is present
$this->assertEquals([], $h->getRequests());
}
public function testLogsConnectionErrors()
{
$request = new Request('GET', '/');
$t = new Transaction(new Client(), $request);
$e = new RequestException('foo', $request);
$ev = new ErrorEvent($t, $e);
$h = new History();
$h->onError($ev);
$this->assertEquals([$request], $h->getRequests());
}