From e342b2d05a0ab368cae8bdfc45678ac73e81b420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Mon, 25 Jan 2016 20:48:44 +0100 Subject: [PATCH] Remove PSR-7 dependency --- composer.json | 3 --- spec/FulfilledPromiseSpec.php | 34 ++++++++++++++-------------------- spec/RejectedPromiseSpec.php | 13 +++++-------- src/FulfilledPromise.php | 16 +++++++--------- src/Promise.php | 4 +--- 5 files changed, 27 insertions(+), 43 deletions(-) diff --git a/composer.json b/composer.json index 85cebc9..360aadc 100644 --- a/composer.json +++ b/composer.json @@ -14,9 +14,6 @@ "email": "mark.sagikazar@gmail.com" } ], - "require": { - "psr/http-message": "^1.0" - }, "require-dev": { "phpspec/phpspec": "^2.4", "henrikbjorn/phpspec-code-coverage" : "^1.0" diff --git a/spec/FulfilledPromiseSpec.php b/spec/FulfilledPromiseSpec.php index 11b1188..cf0199b 100644 --- a/spec/FulfilledPromiseSpec.php +++ b/spec/FulfilledPromiseSpec.php @@ -3,19 +3,17 @@ namespace spec\Http\Promise; use Http\Promise\Promise; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class FulfilledPromiseSpec extends ObjectBehavior { - function let(ResponseInterface $response) + function let() { - $this->beConstructedWith($response); + $this->beConstructedWith('result'); } - function it_is_initializable(ResponseInterface $response) + function it_is_initializable() { $this->shouldHaveType('Http\Promise\FulfilledPromise'); } @@ -25,28 +23,24 @@ function it_is_a_promise() $this->shouldImplement('Http\Promise\Promise'); } - function it_returns_a_fulfilled_promise(ResponseInterface $response) + function it_returns_a_fulfilled_promise() { - $promise = $this->then(function (ResponseInterface $responseReceived) use ($response) { - if (Argument::is($responseReceived)->scoreArgument($response->getWrappedObject())) { - return $response->getWrappedObject(); - } + $promise = $this->then(function ($result) { + return $result; }); $promise->shouldHaveType('Http\Promise\Promise'); $promise->shouldHaveType('Http\Promise\FulfilledPromise'); $promise->getState()->shouldReturn(Promise::FULFILLED); - $promise->wait()->shouldReturn($response); + $promise->wait()->shouldReturn('result'); } - function it_returns_a_rejected_promise(RequestInterface $request, ResponseInterface $response) + function it_returns_a_rejected_promise() { $exception = new \Exception(); - $promise = $this->then(function (ResponseInterface $responseReceived) use ($response, $exception) { - if (Argument::is($responseReceived)->scoreArgument($response->getWrappedObject())) { - throw $exception; - } + $promise = $this->then(function () use ($exception) { + throw $exception; }); $promise->shouldHaveType('Http\Promise\Promise'); @@ -65,13 +59,13 @@ function it_is_in_fulfilled_state() $this->getState()->shouldReturn(Promise::FULFILLED); } - function it_has_a_response(ResponseInterface $response) + function it_has_a_result() { - $this->wait()->shouldReturn($response); + $this->wait()->shouldReturn('result'); } - function it_does_not_unwrap_a_value(ResponseInterface $response) + function it_does_not_unwrap_a_value() { - $this->wait(false)->shouldNotReturn($response); + $this->wait(false)->shouldNotReturn('result'); } } diff --git a/spec/RejectedPromiseSpec.php b/spec/RejectedPromiseSpec.php index a0130a3..ce1df6a 100644 --- a/spec/RejectedPromiseSpec.php +++ b/spec/RejectedPromiseSpec.php @@ -3,7 +3,6 @@ namespace spec\Http\Promise; use Http\Promise\Promise; -use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -24,21 +23,19 @@ function it_is_a_promise() $this->shouldImplement('Http\Promise\Promise'); } - function it_returns_a_fulfilled_promise(ResponseInterface $response) + function it_returns_a_fulfilled_promise() { $exception = new \Exception(); $this->beConstructedWith($exception); - $promise = $this->then(null, function (\Exception $exceptionReceived) use($exception, $response) { - if (Argument::is($exceptionReceived)->scoreArgument($exception)) { - return $response->getWrappedObject(); - } + $promise = $this->then(null, function (\Exception $exceptionReceived) use($exception) { + return 'result'; }); $promise->shouldHaveType('Http\Promise\Promise'); $promise->shouldHaveType('Http\Promise\FulfilledPromise'); $promise->getState()->shouldReturn(Promise::FULFILLED); - $promise->wait()->shouldReturn($response); + $promise->wait()->shouldReturn('result'); } function it_returns_a_rejected_promise() @@ -76,7 +73,7 @@ function it_returns_an_exception() $this->shouldThrow($exception)->duringWait(); } - function it_does_not_unwrap_a_value(ResponseInterface $response) + function it_does_not_unwrap_a_value() { $this->shouldNotThrow('Exception')->duringWait(false); } diff --git a/src/FulfilledPromise.php b/src/FulfilledPromise.php index 3de89d8..f60f686 100644 --- a/src/FulfilledPromise.php +++ b/src/FulfilledPromise.php @@ -2,8 +2,6 @@ namespace Http\Promise; -use Psr\Http\Message\ResponseInterface; - /** * A promise already fulfilled. * @@ -12,16 +10,16 @@ final class FulfilledPromise implements Promise { /** - * @var ResponseInterface + * @var mixed */ - private $response; + private $result; /** - * @param ResponseInterface $response + * @param $result */ - public function __construct(ResponseInterface $response) + public function __construct($result) { - $this->response = $response; + $this->result = $result; } /** @@ -34,7 +32,7 @@ public function then(callable $onFulfilled = null, callable $onRejected = null) } try { - return new self($onFulfilled($this->response)); + return new self($onFulfilled($this->result)); } catch (\Exception $e) { return new RejectedPromise($e); } @@ -54,7 +52,7 @@ public function getState() public function wait($unwrap = true) { if ($unwrap) { - return $this->response; + return $this->result; } } } diff --git a/src/Promise.php b/src/Promise.php index c3511e5..e2cf5f8 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -2,8 +2,6 @@ namespace Http\Promise; -use Psr\Http\Message\ResponseInterface; - /** * Promise represents a value that may not be available yet, but will be resolved at some point in future. * It acts like a proxy to the actual value. @@ -63,7 +61,7 @@ public function getState(); * * @param bool $unwrap Whether to return resolved value / throw reason or not * - * @return ResponseInterface|null Resolved value, null if $unwrap is set to false + * @return mixed Resolved value, null if $unwrap is set to false * * @throws \Exception The rejection reason if $unwrap is set to true and the request failed. */