1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 10:03:27 +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\MagicFutureTrait;
use GuzzleHttp\Ring\Future\FutureInterface; use GuzzleHttp\Ring\Future\FutureInterface;
use GuzzleHttp\Ring\ValidatedDeferredInstance;
use GuzzleHttp\Stream\StreamInterface; use GuzzleHttp\Stream\StreamInterface;
use React\Promise\Deferred;
/** /**
* Represents a response that has not been fulfilled. * Represents a response that has not been fulfilled.
@ -59,15 +59,11 @@ class FutureResponse implements ResponseInterface, FutureInterface
callable $deref, callable $deref,
callable $cancel = null callable $cancel = null
) { ) {
$deferred = new ValidatedDeferredInstance('GuzzleHttp\Message\ResponseInterface'); $deferred = new Deferred();
return new FutureResponse( return new FutureResponse(
$deferred->promise(), $deferred->promise(),
function () use ($deferred, $deref) { function () use ($deferred, $deref) {
try { $deferred->resolve($deref());
$deferred->resolve(call_user_func($deref));
} catch (\Exception $e) {
$deferred->reject($e);
}
}, },
$cancel $cancel
); );

View File

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