1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 01:53:58 +01:00

Not relying on validated deferred

This commit is contained in:
Michael Dowling 2014-10-05 18:59:19 -07:00
parent b1fb453098
commit 17fe94cf01
2 changed files with 7 additions and 22 deletions

View File

@ -3,8 +3,8 @@ namespace GuzzleHttp\Message;
use GuzzleHttp\Ring\Future\MagicFutureTrait;
use GuzzleHttp\Ring\Future\FutureInterface;
use GuzzleHttp\Ring\ValidatedDeferredInstance;
use GuzzleHttp\Stream\StreamInterface;
use React\Promise\Deferred;
/**
* Represents a response that has not been fulfilled.
@ -59,15 +59,11 @@ class FutureResponse implements ResponseInterface, FutureInterface
callable $deref,
callable $cancel = null
) {
$deferred = new ValidatedDeferredInstance('GuzzleHttp\Message\ResponseInterface');
$deferred = new Deferred();
return new FutureResponse(
$deferred->promise(),
function () use ($deferred, $deref) {
try {
$deferred->resolve(call_user_func($deref));
} catch (\Exception $e) {
$deferred->reject($e);
}
$deferred->resolve($deref());
},
$cancel
);

View File

@ -18,16 +18,6 @@ class FutureResponseTest extends \PHPUnit_Framework_TestCase
$f->foo;
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected the resolved value to be an instance of "GuzzleHttp\Message\ResponseInterface", but got NULL
*/
public function testEnsuresDerefReturnsTransaction()
{
$f = FutureResponse::createFuture(function () {});
$f->getStatusCode();
}
public function testDoesTheSameAsResponseWhenDereferenced()
{
$str = Stream::factory('foo');
@ -138,16 +128,15 @@ class FutureResponseTest extends \PHPUnit_Framework_TestCase
public function testExceptionInToStringTriggersError()
{
$future = FutureResponse::createFuture(function () {});
$future = FutureResponse::createFuture(function () {
throw new \Exception('foo');
});
$err = '';
set_error_handler(function () use (&$err) {
$err = func_get_args()[1];
});
echo $future;
restore_error_handler();
$this->assertContains(
'Expected the resolved value to be an instance of "GuzzleHttp\Message\ResponseInterface", but got NULL',
$err
);
$this->assertContains('foo', $err);
}
}