Skip to content

Commit

Permalink
Merge pull request #70 from City-of-Helsinki/UHF-6339
Browse files Browse the repository at this point in the history
UHF-6339: Method to initialize history middleware http stub
  • Loading branch information
tuutti authored Aug 23, 2022
2 parents c426855 + d014169 commit c585917
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/src/Traits/ApiTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;

/**
* Provides shared functionality for api tests.
Expand All @@ -30,6 +31,26 @@ protected function createMockHttpClient(array $responses) : Client {
return new Client(['handler' => $handlerStack]);
}

/**
* Creates HTTP history middleware client stub.
*
* @param array $container
* The container.
* @param \Psr\Http\Message\ResponseInterface[]|\GuzzleHttp\Exception\GuzzleException[] $responses
* The expected responses.
*
* @return \GuzzleHttp\Client
* The client.
*/
protected function createMockHistoryMiddlewareHttpClient(array &$container, array $responses = []) : Client {
$history = Middleware::history($container);
$mock = new MockHandler($responses);
$handlerStack = HandlerStack::create($mock);
$handlerStack->push($history);

return new Client(['handler' => $handlerStack]);
}

/**
* Enable translation for given entity types.
*
Expand Down

0 comments on commit c585917

Please sign in to comment.