Files
portal/app/tests/Feature/Autopodbor/DeepStudyToggleTest.php
T
Дмитрий a75705c80e style(autopodbor): pint — причесать миграции/фетчер/тесты перед релизом
Стиль-only (braces_position, ordered_imports, fully_qualified_strict_types и т.п.),
поведение не меняется. Autopodbor 476/476 зелёный после причёсывания.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 14:35:22 +03:00

70 lines
2.7 KiB
PHP

<?php
use App\Services\Autopodbor\Agent\Dto\StudyCompetitorRequest;
use App\Services\Autopodbor\Agent\Dto\StudyCompetitorResult;
use App\Services\Autopodbor\Agent\FakeCompetitorAgent;
use App\Services\Autopodbor\Agent\Fetch\FetchedSite;
use App\Services\Autopodbor\Agent\Fetch\Fetcher;
use App\Services\Autopodbor\Agent\RealCompetitorAgent;
use App\Services\Autopodbor\Agent\Study\Fingerprint;
use App\Services\Autopodbor\Agent\Study\SourceCollector;
it('deep_study ВКЛ → studyCompetitor идёт через SourceCollector', function () {
config()->set('autopodbor.deep_study', true);
$deep = new class implements SourceCollector
{
public function collect(Fingerprint $fp): array
{
return [[
'signal_type' => 'call', 'identifier' => '73912920000',
'phone_kind' => 'real', 'phone_type' => 'city',
'provenance_url' => null, 'provenance_label' => 'в коде сайта',
'where_found' => [['label' => 'в коде сайта', 'url' => null]],
'office' => null, 'confirmations' => 1,
]];
}
};
$fetcher = new class implements Fetcher
{
public function site(string $url): FetchedSite
{
throw new LogicException('старый путь не должен вызываться при deep');
}
public function directory(string $url): array
{
return [];
}
};
$agent = new RealCompetitorAgent($fetcher, new FakeCompetitorAgent, deep: $deep);
$res = $agent->studyCompetitor(new StudyCompetitorRequest(['name' => 'X', 'site_url' => 'x.ru'], 29));
expect($res->sources[0]['identifier'])->toBe('73912920000');
});
it('deep_study ВЫКЛ → SourceCollector НЕ вызывается (старый путь)', function () {
config()->set('autopodbor.deep_study', false);
$deep = new class implements SourceCollector
{
public function collect(Fingerprint $fp): array
{
throw new LogicException('deep не должен вызываться при выкл');
}
};
$fetcher = new class implements Fetcher
{
public function site(string $url): FetchedSite
{
return new FetchedSite($url, '');
}
public function directory(string $url): array
{
return [];
}
};
$agent = new RealCompetitorAgent($fetcher, new FakeCompetitorAgent, deep: $deep);
$res = $agent->studyCompetitor(new StudyCompetitorRequest(['name' => 'X', 'site_url' => 'x.ru'], 29));
// старый путь отработал, deep не тронут (иначе бросило бы)
expect($res)->toBeInstanceOf(StudyCompetitorResult::class);
});