new FetchedSite( url: 'https://k.ru', rawHtml: 'x8(391)111-22-33', visiblePhones: ['8(391)111-22-33'], ), ], cards: [ 'https://2gis.ru/firm/1' => [ new DirectoryCard(number: '8(391)292-00-00', office: 'Единая справочная', url: 'https://2gis.ru/firm/1', source: '2ГИС'), ], ], ); $agent = new RealCompetitorAgent($fetcher, new FakeCompetitorAgent); $res = $agent->studyCompetitor(new StudyCompetitorRequest( competitor: ['name' => 'КрасЛомбард', 'site_url' => 'k.ru', 'directory_urls' => ['https://2gis.ru/firm/1']], regionCode: 391, )); $calls = array_values(array_filter($res->sources, fn ($s) => $s['signal_type'] === 'call')); $sites = array_values(array_filter($res->sources, fn ($s) => $s['signal_type'] === 'site')); // настоящий 292-00-00 (код+2ГИС = 2 подтверждения) выше подменного 111-22-33 expect($calls[0]['identifier'])->toBe('73912920000'); expect($calls[0]['phone_kind'])->toBe('real'); expect(end($calls)['phone_kind'])->toBe('substitute'); // сайт конкурента — отдельной строкой expect(collect($sites)->pluck('identifier'))->toContain('k.ru'); }); it('сводит филиалы из разных справочников: больше подтверждений — выше', function () { $fetcher = new FakeFetcher( sites: ['https://k.ru' => new FetchedSite(url: 'https://k.ru', rawHtml: 'x')], cards: [ 'https://2gis.ru/firm/1' => [new DirectoryCard(number: '8(391)292-00-00', office: 'Справочная', url: 'https://2gis.ru/firm/1', source: '2ГИС')], 'https://yandex.ru/maps/2' => [new DirectoryCard(number: '8(391)281-70-70', office: 'Кр. рабочий, 61', url: 'https://yandex.ru/maps/2', source: 'Яндекс.Карты')], ], ); $agent = new RealCompetitorAgent($fetcher, new FakeCompetitorAgent); $res = $agent->studyCompetitor(new StudyCompetitorRequest( competitor: ['name' => 'КрасЛомбард', 'site_url' => 'k.ru', 'directory_urls' => ['https://2gis.ru/firm/1', 'https://yandex.ru/maps/2']], regionCode: 391, )); $calls = array_values(array_filter($res->sources, fn ($s) => $s['signal_type'] === 'call')); // 292-00-00: код + 2ГИС = 2 подтверждения → выше, чем 281-70-70 (только Яндекс = 1) expect($calls[0]['identifier'])->toBe('73912920000'); expect(collect($calls)->pluck('identifier'))->toContain('73912817070'); });