1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Removed use of HttpFetcher

- Fixed some existing issues in new aligned process.
- Manually tested each external call scenario.
This commit is contained in:
Dan Brown
2023-09-08 17:16:57 +01:00
parent a8b5652210
commit 06490f624c
7 changed files with 54 additions and 104 deletions

View File

@ -25,4 +25,9 @@ class HttpClientHistory
{
return $this->requestAt($this->requestCount() - 1);
}
public function all(): array
{
return $this->container;
}
}

View File

@ -7,6 +7,7 @@ use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request as GuzzleRequest;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Client\ClientInterface;
class HttpRequestService
@ -16,7 +17,7 @@ class HttpRequestService
/**
* Build a new http client for sending requests on.
*/
public function buildClient(int $timeout, array $options): ClientInterface
public function buildClient(int $timeout, array $options = []): ClientInterface
{
$defaultOptions = [
'timeout' => $timeout,
@ -40,8 +41,16 @@ class HttpRequestService
* Returns history which can then be queried.
* @link https://docs.guzzlephp.org/en/stable/testing.html#history-middleware
*/
public function mockClient(array $responses = []): HttpClientHistory
public function mockClient(array $responses = [], bool $pad = true): HttpClientHistory
{
// By default, we pad out the responses with 10 successful values so that requests will be
// properly recorded for inspection. Otherwise, we can't later check if we're received
// too many requests.
if ($pad) {
$response = new Response(200, [], 'success');
$responses = array_merge($responses, array_fill(0, 10, $response));
}
$container = [];
$history = Middleware::history($container);
$mock = new MockHandler($responses);