feat: refonte du gestionnaire de chapitres pour intégrer la génération de fichiers CBZ, le téléchargement d'images en lot et la gestion des requêtes de scraping, avec mise à jour des interfaces et des modèles associés
This commit is contained in:
parent
cdee6f77fc
commit
d7088b14c2
48
tests/Domain/Scraping/Adapter/InMemoryImageDownloader.php
Normal file
48
tests/Domain/Scraping/Adapter/InMemoryImageDownloader.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Domain\Scraping\Adapter;
|
||||
|
||||
use App\Domain\Scraping\Domain\Contract\Service\ImageDownloaderInterface;
|
||||
use App\Domain\Scraping\Domain\Model\ValueObject\DownloadResult;
|
||||
use App\Domain\Scraping\Domain\Model\ValueObject\TempDirectory;
|
||||
|
||||
class InMemoryImageDownloader implements ImageDownloaderInterface
|
||||
{
|
||||
private array $downloadedFiles = [];
|
||||
private ?\Exception $shouldThrowException = null;
|
||||
|
||||
public function download(string $url, string $destination): void
|
||||
{
|
||||
if ($this->shouldThrowException) {
|
||||
throw $this->shouldThrowException;
|
||||
}
|
||||
|
||||
$this->downloadedFiles[$url] = $destination;
|
||||
}
|
||||
|
||||
public function downloadBatch(array $urls, TempDirectory $tempDir, string $jobId): array
|
||||
{
|
||||
if ($this->shouldThrowException) {
|
||||
throw $this->shouldThrowException;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
foreach ($urls as $index => $url) {
|
||||
$destination = sprintf('%s/%03d.jpg', $tempDir->getPath(), $index + 1);
|
||||
$this->download($url, $destination);
|
||||
$results[] = new DownloadResult($destination, $url);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function simulateError(\Exception $exception): void
|
||||
{
|
||||
$this->shouldThrowException = $exception;
|
||||
}
|
||||
|
||||
public function getDownloadedFiles(): array
|
||||
{
|
||||
return $this->downloadedFiles;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user