2026-06-30 12:41:18 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Services\Autopodbor\Agent\Fetch\CompositeFetcher;
|
|
|
|
|
use App\Services\Autopodbor\Agent\Fetch\DirectoryCard;
|
|
|
|
|
use App\Services\Autopodbor\Agent\Fetch\FetchedSite;
|
2026-06-30 21:06:10 +03:00
|
|
|
use App\Services\Autopodbor\Agent\Fetch\Fetcher;
|
2026-06-30 12:41:18 +03:00
|
|
|
|
|
|
|
|
function onlySiteFetcher(): Fetcher
|
|
|
|
|
{
|
|
|
|
|
return new class implements Fetcher
|
|
|
|
|
{
|
|
|
|
|
public function site(string $url): FetchedSite
|
|
|
|
|
{
|
|
|
|
|
return new FetchedSite(url: $url, rawHtml: 'ИЗ-САЙТ-ЗАГРУЗЧИКА');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function directory(string $url): array
|
|
|
|
|
{
|
|
|
|
|
throw new RuntimeException('directory не должен идти в site-загрузчик');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onlyDirectoryFetcher(): Fetcher
|
|
|
|
|
{
|
|
|
|
|
return new class implements Fetcher
|
|
|
|
|
{
|
|
|
|
|
public function site(string $url): FetchedSite
|
|
|
|
|
{
|
|
|
|
|
throw new RuntimeException('site не должен идти в directory-загрузчик');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function directory(string $url): array
|
|
|
|
|
{
|
|
|
|
|
return [new DirectoryCard(number: '+73912920000', office: 'Мира, 10', url: $url, source: '2ГИС')];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it('site() идёт в site-загрузчик, directory() — в directory-загрузчик', function () {
|
|
|
|
|
$c = new CompositeFetcher(onlySiteFetcher(), onlyDirectoryFetcher());
|
|
|
|
|
|
|
|
|
|
expect($c->site('https://k.ru')->rawHtml)->toBe('ИЗ-САЙТ-ЗАГРУЗЧИКА');
|
|
|
|
|
|
|
|
|
|
$cards = $c->directory('https://2gis.ru/x');
|
|
|
|
|
expect($cards)->toHaveCount(1)
|
|
|
|
|
->and($cards[0]->number)->toBe('+73912920000')
|
|
|
|
|
->and($cards[0]->source)->toBe('2ГИС');
|
|
|
|
|
});
|