mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-25 02:22:57 +01:00
When a networking error occurs, the future response that is created for the transaction does not receive an exception until after the future is waited on. When calling getResponse() in an event that is emitted after a networking error, the response returned will be a future with no actual data to use and throws when accessed. This commit updated these events to return null if the response of the transaction is a future. In these cases, it means that the response did not complete successfully. I've also added a new method to make this more explicit: hasResponse(). Closes #867.
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
namespace GuzzleHttp\Tests;
|
|
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Event\AbstractTransferEvent;
|
|
use GuzzleHttp\Pool;
|
|
|
|
class IntegrationTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @issue https://github.com/guzzle/guzzle/issues/867
|
|
*/
|
|
public function testDoesNotFailInEventSystemForNetworkError()
|
|
{
|
|
$c = new Client();
|
|
$r = $c->createRequest(
|
|
'GET',
|
|
Server::$url,
|
|
[
|
|
'timeout' => 1,
|
|
'connect_timeout' => 1,
|
|
'proxy' => 'http://127.0.0.1:123/foo'
|
|
]
|
|
);
|
|
|
|
$events = [];
|
|
$fn = function(AbstractTransferEvent $event) use (&$events) {
|
|
$events[] = [
|
|
get_class($event),
|
|
$event->hasResponse(),
|
|
$event->getResponse()
|
|
];
|
|
};
|
|
|
|
$pool = new Pool($c, [$r], [
|
|
'error' => $fn,
|
|
'end' => $fn
|
|
]);
|
|
|
|
$pool->wait();
|
|
|
|
$this->assertCount(2, $events);
|
|
$this->assertEquals('GuzzleHttp\Event\ErrorEvent', $events[0][0]);
|
|
$this->assertFalse($events[0][1]);
|
|
$this->assertNull($events[0][2]);
|
|
|
|
$this->assertEquals('GuzzleHttp\Event\EndEvent', $events[1][0]);
|
|
$this->assertFalse($events[1][1]);
|
|
$this->assertNull($events[1][2]);
|
|
}
|
|
}
|