48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Domain\Scraping\Adapter;
|
|
|
|
use App\Domain\Scraping\Domain\Contract\Service\ScraperInterface;
|
|
use App\Domain\Scraping\Domain\Model\ScrapingJob;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
class InMemoryScraperAdapter implements ScraperInterface
|
|
{
|
|
private array $jobs = [];
|
|
private ?\Exception $shouldThrowException = null;
|
|
|
|
public function createScrapingJob(string $mangaId, string $chapterId, string $sourceId): ScrapingJob
|
|
{
|
|
if ($this->shouldThrowException) {
|
|
throw $this->shouldThrowException;
|
|
}
|
|
|
|
$job = new ScrapingJob(Uuid::uuid4(), $mangaId, $chapterId, $sourceId);
|
|
$this->jobs[] = $job;
|
|
|
|
return $job;
|
|
}
|
|
|
|
public function scrape(ScrapingJob $job): void
|
|
{
|
|
if ($this->shouldThrowException) {
|
|
throw $this->shouldThrowException;
|
|
}
|
|
}
|
|
|
|
public function simulateError(\Exception $exception): void
|
|
{
|
|
$this->shouldThrowException = $exception;
|
|
}
|
|
|
|
public function getJobs(): array
|
|
{
|
|
return $this->jobs;
|
|
}
|
|
|
|
public function supports(string $sourceType): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|