events/Classes/Service/DestinationDataImportService/DataFetcher.php
Daniel Siepmann 0e5cd38176 Add first basic functional test for import
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.
2021-12-16 09:08:16 +01:00

55 lines
1.3 KiB
PHP

<?php
namespace Wrm\Events\Service\DestinationDataImportService;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Provides API to fetch data from remote.
*
* Only partially migrated from service to here.
* Further calls need to be migrated.
*/
class DataFetcher
{
/**
* @var RequestFactoryInterface
*/
private $requestFactory;
/**
* @var GuzzleClientInterface
*/
private $client;
public function __construct(
RequestFactoryInterface $requestFactory,
GuzzleClientInterface $client
) {
$this->requestFactory = $requestFactory;
$this->client = $client;
}
public function fetchImage(string $url): ResponseInterface
{
// Keep after TYPO3 10 was dropped
if ($this->client instanceof ClientInterface) {
return $this->client->sendRequest(
$this->requestFactory->createRequest(
'GET',
$url
)
);
}
// Drop once TYPO3 10 support was dropped
return $this->client->request(
'GET',
$url,
[]
);
}
}