35 lines
904 B
PHP
35 lines
904 B
PHP
<?php
|
|
|
|
namespace App\Tests\Domain\Scraping\Adapter;
|
|
|
|
use App\Domain\Scraping\Domain\Contract\Service\ScraperInterface;
|
|
use App\Domain\Scraping\Domain\Model\ValueObject\ScrapingRequest;
|
|
use App\Domain\Scraping\Domain\Model\ValueObject\ScrapingResult;
|
|
|
|
class InMemoryScraperAdapter implements ScraperInterface
|
|
{
|
|
private ?\Exception $shouldThrowException = null;
|
|
|
|
public function scrape(ScrapingRequest $request): ScrapingResult
|
|
{
|
|
if ($this->shouldThrowException) {
|
|
throw $this->shouldThrowException;
|
|
}
|
|
|
|
return new ScrapingResult(
|
|
['http://example.com/image1.jpg', 'http://example.com/image2.jpg'],
|
|
2
|
|
);
|
|
}
|
|
|
|
public function simulateError(\Exception $exception): void
|
|
{
|
|
$this->shouldThrowException = $exception;
|
|
}
|
|
|
|
public function supports(string $sourceType): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|