Skip to content

Commit ac3d749

Browse files
Nyholmdbu
authored andcommitted
Start version 2
1 parent 04d4829 commit ac3d749

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

.travis.yml

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ cache:
77
- $HOME/.composer/cache/files
88

99
php:
10-
- 5.5
11-
- 5.6
12-
- 7.0
1310
- 7.1
1411
- 7.2
1512
- 7.3

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 2.0.0 - unreleased
4+
5+
### Changed
6+
7+
- Client::getLastRequest returns `null` instead of `false` when on requests have been recorded yet.
8+
39
## 1.2.0 - unreleased
410

511
### Added

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^5.5 || ^7.0",
15-
"php-http/httplug": "^1.0 || ^2.0",
16-
"php-http/client-common": "^1.9 || ^2.0",
14+
"php": "^7.1",
15+
"php-http/httplug": "^2.0",
16+
"php-http/client-common": "^2.0",
1717
"php-http/discovery": "^1.0",
1818
"php-http/message-factory": "^1.0"
1919
},
@@ -36,7 +36,7 @@
3636
},
3737
"extra": {
3838
"branch-alias": {
39-
"dev-master": "1.2-dev"
39+
"dev-master": "2.0-dev"
4040
}
4141
},
4242
"prefer-stable": true,

spec/ClientSpec.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function it_returns_the_last_request(RequestInterface $request, ResponseInterfac
8080
$this->getLastRequest()->shouldReturn($request);
8181
}
8282

83-
function it_returns_false_when_there_is_no_last_request()
83+
function it_returns_null_when_there_is_no_last_request()
8484
{
85-
$this->getLastRequest()->shouldReturn(false);
85+
$this->getLastRequest()->shouldReturn(null);
8686
}
8787
}

src/Client.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Http\Mock;
44

55
use Http\Client\Common\HttpAsyncClientEmulator;
6-
use Http\Client\Common\VersionBridgeClient;
76
use Http\Client\Exception;
87
use Http\Client\HttpAsyncClient;
98
use Http\Client\HttpClient;
@@ -23,7 +22,6 @@
2322
class Client implements HttpClient, HttpAsyncClient
2423
{
2524
use HttpAsyncClientEmulator;
26-
use VersionBridgeClient;
2725

2826
/**
2927
* @var ResponseFactory
@@ -61,9 +59,15 @@ public function __construct(ResponseFactory $responseFactory = null)
6159
}
6260

6361
/**
64-
* {@inheritdoc}
62+
* This will in order:
63+
*
64+
* - Throw the next exception in the list and advance
65+
* - Return the next response in the list and advance
66+
* - Throw the default exception if set (forever)
67+
* - Return the default response if set (forever)
68+
* - Create a new empty response with the response factory
6569
*/
66-
public function doSendRequest(RequestInterface $request)
70+
public function sendRequest(RequestInterface $request): ResponseInterface
6771
{
6872
$this->requests[] = $request;
6973

@@ -100,7 +104,7 @@ public function addException(\Exception $exception)
100104
*
101105
* If both a default exception and a default response are set, the exception will be thrown.
102106
*/
103-
public function setDefaultException(\Exception $defaultException = null)
107+
public function setDefaultException(?\Exception $defaultException)
104108
{
105109
$this->defaultException = $defaultException;
106110
}
@@ -116,7 +120,7 @@ public function addResponse(ResponseInterface $response)
116120
/**
117121
* Sets the default response to be returned when the list of added exceptions and responses is exhausted.
118122
*/
119-
public function setDefaultResponse(ResponseInterface $defaultResponse = null)
123+
public function setDefaultResponse(?ResponseInterface $defaultResponse)
120124
{
121125
$this->defaultResponse = $defaultResponse;
122126
}
@@ -126,13 +130,13 @@ public function setDefaultResponse(ResponseInterface $defaultResponse = null)
126130
*
127131
* @return RequestInterface[]
128132
*/
129-
public function getRequests()
133+
public function getRequests(): array
130134
{
131135
return $this->requests;
132136
}
133137

134-
public function getLastRequest()
138+
public function getLastRequest(): ?RequestInterface
135139
{
136-
return end($this->requests);
140+
return end($this->requests) ?: null;
137141
}
138142
}

0 commit comments

Comments
 (0)