-
Notifications
You must be signed in to change notification settings - Fork 17
WIP: upgrade to HTTPlug 2.0 #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,10 @@ | |
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* HTTP client mock. | ||
* An implementation of the HTTP client that is useful for automated tests. | ||
* | ||
* This mock is most useful in tests. It does not send requests but stores them | ||
* for later retrieval. Additionally, you can set an exception to test | ||
* exception handling. | ||
* This mock does not send requests but stores them for later retrieval. | ||
* You can configure the mock with responses to return and/or exceptions to throw. | ||
* | ||
* @author David de Boer <[email protected]> | ||
*/ | ||
|
@@ -54,9 +53,6 @@ class Client implements HttpClient, HttpAsyncClient | |
*/ | ||
private $defaultException; | ||
|
||
/** | ||
* @param ResponseFactory|null $responseFactory | ||
*/ | ||
public function __construct(ResponseFactory $responseFactory = null) | ||
{ | ||
$this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find(); | ||
|
@@ -65,7 +61,7 @@ public function __construct(ResponseFactory $responseFactory = null) | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function sendRequest(RequestInterface $request) | ||
public function sendRequest(RequestInterface $request): ResponseInterface | ||
{ | ||
$this->requests[] = $request; | ||
|
||
|
@@ -91,8 +87,6 @@ public function sendRequest(RequestInterface $request) | |
|
||
/** | ||
* Adds an exception that will be thrown. | ||
* | ||
* @param \Exception $exception | ||
*/ | ||
public function addException(\Exception $exception) | ||
{ | ||
|
@@ -103,18 +97,14 @@ public function addException(\Exception $exception) | |
* Sets the default exception to throw when the list of added exceptions and responses is exhausted. | ||
* | ||
* If both a default exception and a default response are set, the exception will be thrown. | ||
* | ||
* @param \Exception|null $defaultException | ||
*/ | ||
public function setDefaultException(\Exception $defaultException = null) | ||
public function setDefaultException(?\Exception $defaultException) | ||
{ | ||
$this->defaultException = $defaultException; | ||
} | ||
|
||
/** | ||
* Adds a response that will be returned. | ||
* | ||
* @param ResponseInterface $response | ||
* Adds a response that will be returned in first in first out order. | ||
*/ | ||
public function addResponse(ResponseInterface $response) | ||
{ | ||
|
@@ -123,10 +113,8 @@ public function addResponse(ResponseInterface $response) | |
|
||
/** | ||
* Sets the default response to be returned when the list of added exceptions and responses is exhausted. | ||
* | ||
* @param ResponseInterface|null $defaultResponse | ||
*/ | ||
public function setDefaultResponse(ResponseInterface $defaultResponse = null) | ||
public function setDefaultResponse(?ResponseInterface $defaultResponse) | ||
{ | ||
$this->defaultResponse = $defaultResponse; | ||
} | ||
|
@@ -136,16 +124,13 @@ public function setDefaultResponse(ResponseInterface $defaultResponse = null) | |
* | ||
* @return RequestInterface[] | ||
*/ | ||
public function getRequests() | ||
public function getRequests(): array | ||
{ | ||
return $this->requests; | ||
} | ||
|
||
/** | ||
* @return RequestInterface|false | ||
*/ | ||
public function getLastRequest() | ||
public function getLastRequest(): ?RequestInterface | ||
{ | ||
return end($this->requests); | ||
return end($this->requests) ?: null; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
We should not allow someone doing
$e->setDefaultException();
This change make sure you have to do
$e->setDefaultException(null);