Files
portal/app/tests/Unit/Autopodbor/Fetch/CompositeFetcherTest.php
T
Дмитрий f248c37d1b feat(автоподбор шаг2): CompositeFetcher — сайт и справочники разными путями
Один Fetcher для движка: site() → богатый загрузчик (curl+Playwright,
видимые/пул/контакты), directory() → антибот-загрузчик (xfetch).
Готовит провод реального агента (Plan C). TDD: Autopodbor 47/47.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 12:41:18 +03:00

50 lines
1.6 KiB
PHP

<?php
use App\Services\Autopodbor\Agent\Fetch\CompositeFetcher;
use App\Services\Autopodbor\Agent\Fetch\DirectoryCard;
use App\Services\Autopodbor\Agent\Fetch\Fetcher;
use App\Services\Autopodbor\Agent\Fetch\FetchedSite;
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ГИС');
});