Skip to content

Commit 0f930b6

Browse files
committed
Merge pull request #9 from php-http/remove_response
Remove PSR-7 dependency
2 parents 52ec7e6 + e342b2d commit 0f930b6

File tree

5 files changed

+27
-43
lines changed

5 files changed

+27
-43
lines changed

Diff for: composer.json

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"email": "[email protected]"
1515
}
1616
],
17-
"require": {
18-
"psr/http-message": "^1.0"
19-
},
2017
"require-dev": {
2118
"phpspec/phpspec": "^2.4",
2219
"henrikbjorn/phpspec-code-coverage" : "^1.0"

Diff for: spec/FulfilledPromiseSpec.php

+14-20
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
namespace spec\Http\Promise;
44

55
use Http\Promise\Promise;
6-
use Psr\Http\Message\RequestInterface;
7-
use Psr\Http\Message\ResponseInterface;
86
use PhpSpec\ObjectBehavior;
97
use Prophecy\Argument;
108

119
class FulfilledPromiseSpec extends ObjectBehavior
1210
{
13-
function let(ResponseInterface $response)
11+
function let()
1412
{
15-
$this->beConstructedWith($response);
13+
$this->beConstructedWith('result');
1614
}
1715

18-
function it_is_initializable(ResponseInterface $response)
16+
function it_is_initializable()
1917
{
2018
$this->shouldHaveType('Http\Promise\FulfilledPromise');
2119
}
@@ -25,28 +23,24 @@ function it_is_a_promise()
2523
$this->shouldImplement('Http\Promise\Promise');
2624
}
2725

28-
function it_returns_a_fulfilled_promise(ResponseInterface $response)
26+
function it_returns_a_fulfilled_promise()
2927
{
30-
$promise = $this->then(function (ResponseInterface $responseReceived) use ($response) {
31-
if (Argument::is($responseReceived)->scoreArgument($response->getWrappedObject())) {
32-
return $response->getWrappedObject();
33-
}
28+
$promise = $this->then(function ($result) {
29+
return $result;
3430
});
3531

3632
$promise->shouldHaveType('Http\Promise\Promise');
3733
$promise->shouldHaveType('Http\Promise\FulfilledPromise');
3834
$promise->getState()->shouldReturn(Promise::FULFILLED);
39-
$promise->wait()->shouldReturn($response);
35+
$promise->wait()->shouldReturn('result');
4036
}
4137

42-
function it_returns_a_rejected_promise(RequestInterface $request, ResponseInterface $response)
38+
function it_returns_a_rejected_promise()
4339
{
4440
$exception = new \Exception();
4541

46-
$promise = $this->then(function (ResponseInterface $responseReceived) use ($response, $exception) {
47-
if (Argument::is($responseReceived)->scoreArgument($response->getWrappedObject())) {
48-
throw $exception;
49-
}
42+
$promise = $this->then(function () use ($exception) {
43+
throw $exception;
5044
});
5145

5246
$promise->shouldHaveType('Http\Promise\Promise');
@@ -65,13 +59,13 @@ function it_is_in_fulfilled_state()
6559
$this->getState()->shouldReturn(Promise::FULFILLED);
6660
}
6761

68-
function it_has_a_response(ResponseInterface $response)
62+
function it_has_a_result()
6963
{
70-
$this->wait()->shouldReturn($response);
64+
$this->wait()->shouldReturn('result');
7165
}
7266

73-
function it_does_not_unwrap_a_value(ResponseInterface $response)
67+
function it_does_not_unwrap_a_value()
7468
{
75-
$this->wait(false)->shouldNotReturn($response);
69+
$this->wait(false)->shouldNotReturn('result');
7670
}
7771
}

Diff for: spec/RejectedPromiseSpec.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace spec\Http\Promise;
44

55
use Http\Promise\Promise;
6-
use Psr\Http\Message\ResponseInterface;
76
use PhpSpec\ObjectBehavior;
87
use Prophecy\Argument;
98

@@ -24,21 +23,19 @@ function it_is_a_promise()
2423
$this->shouldImplement('Http\Promise\Promise');
2524
}
2625

27-
function it_returns_a_fulfilled_promise(ResponseInterface $response)
26+
function it_returns_a_fulfilled_promise()
2827
{
2928
$exception = new \Exception();
3029
$this->beConstructedWith($exception);
3130

32-
$promise = $this->then(null, function (\Exception $exceptionReceived) use($exception, $response) {
33-
if (Argument::is($exceptionReceived)->scoreArgument($exception)) {
34-
return $response->getWrappedObject();
35-
}
31+
$promise = $this->then(null, function (\Exception $exceptionReceived) use($exception) {
32+
return 'result';
3633
});
3734

3835
$promise->shouldHaveType('Http\Promise\Promise');
3936
$promise->shouldHaveType('Http\Promise\FulfilledPromise');
4037
$promise->getState()->shouldReturn(Promise::FULFILLED);
41-
$promise->wait()->shouldReturn($response);
38+
$promise->wait()->shouldReturn('result');
4239
}
4340

4441
function it_returns_a_rejected_promise()
@@ -76,7 +73,7 @@ function it_returns_an_exception()
7673
$this->shouldThrow($exception)->duringWait();
7774
}
7875

79-
function it_does_not_unwrap_a_value(ResponseInterface $response)
76+
function it_does_not_unwrap_a_value()
8077
{
8178
$this->shouldNotThrow('Exception')->duringWait(false);
8279
}

Diff for: src/FulfilledPromise.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Http\Promise;
44

5-
use Psr\Http\Message\ResponseInterface;
6-
75
/**
86
* A promise already fulfilled.
97
*
@@ -12,16 +10,16 @@
1210
final class FulfilledPromise implements Promise
1311
{
1412
/**
15-
* @var ResponseInterface
13+
* @var mixed
1614
*/
17-
private $response;
15+
private $result;
1816

1917
/**
20-
* @param ResponseInterface $response
18+
* @param $result
2119
*/
22-
public function __construct(ResponseInterface $response)
20+
public function __construct($result)
2321
{
24-
$this->response = $response;
22+
$this->result = $result;
2523
}
2624

2725
/**
@@ -34,7 +32,7 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
3432
}
3533

3634
try {
37-
return new self($onFulfilled($this->response));
35+
return new self($onFulfilled($this->result));
3836
} catch (\Exception $e) {
3937
return new RejectedPromise($e);
4038
}
@@ -54,7 +52,7 @@ public function getState()
5452
public function wait($unwrap = true)
5553
{
5654
if ($unwrap) {
57-
return $this->response;
55+
return $this->result;
5856
}
5957
}
6058
}

Diff for: src/Promise.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Http\Promise;
44

5-
use Psr\Http\Message\ResponseInterface;
6-
75
/**
86
* Promise represents a value that may not be available yet, but will be resolved at some point in future.
97
* It acts like a proxy to the actual value.
@@ -63,7 +61,7 @@ public function getState();
6361
*
6462
* @param bool $unwrap Whether to return resolved value / throw reason or not
6563
*
66-
* @return ResponseInterface|null Resolved value, null if $unwrap is set to false
64+
* @return mixed Resolved value, null if $unwrap is set to false
6765
*
6866
* @throws \Exception The rejection reason if $unwrap is set to true and the request failed.
6967
*/

0 commit comments

Comments
 (0)