feat: firsts unit tests for ScrapeChapterHandler.php
This commit is contained in:
parent
21fcdd1084
commit
89570ad951
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Scraping\Infrastructure\Service;
|
||||
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class ImageDownloader
|
||||
{
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $httpClient
|
||||
) {}
|
||||
|
||||
public function download(string $url, string $destination): void
|
||||
{
|
||||
$response = $this->httpClient->request('GET', $url);
|
||||
|
||||
if (!str_starts_with($response->getHeaders()['content-type'][0], 'image/')) {
|
||||
throw new \RuntimeException('Invalid content type');
|
||||
}
|
||||
|
||||
file_put_contents($destination, $response->getContent());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user