mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-10 06:36:10 +01:00
Daniel Siepmann
0e5cd38176
The test ensures import runs with a small example set of events. We needed to alter fetching of images, in order to properly mock responses.
38 lines
1 KiB
PHP
38 lines
1 KiB
PHP
<?php
|
|
|
|
namespace Wrm\Events\Tests;
|
|
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\HandlerStack;
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
use GuzzleHttp\Middleware;
|
|
use GuzzleHttp\Psr7\Response;
|
|
|
|
/**
|
|
* Must only be used within tests.
|
|
*/
|
|
class ClientFactory
|
|
{
|
|
/**
|
|
* Use this to create a new client which will return provided responses.
|
|
*
|
|
* You can use the $historyContainer to assert actual requests afterwards,
|
|
* e.g. assert that urls or headers match.
|
|
*
|
|
* @see https://susi.dev/mock-http-api-responses-with-guzzle-psr-18-psr-7/
|
|
*
|
|
* @param Response[] $responses
|
|
* @param array{'request': Request, 'response': Response, 'error': null}[] $historyContainer
|
|
*/
|
|
public static function createClientWithHistory(
|
|
array $responses,
|
|
array &$historyContainer
|
|
): Client {
|
|
$history = Middleware::history($historyContainer);
|
|
|
|
$handlerStack = HandlerStack::create(new MockHandler($responses));
|
|
$handlerStack->push($history);
|
|
|
|
return new Client(['handler' => $handlerStack]);
|
|
}
|
|
}
|