41 lines
1.7 KiB
PHP
41 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
use App\Services\Autopodbor\Agent\Study\CompositePhoneReverse;
|
||
|
|
use App\Services\Autopodbor\Agent\Study\PhoneExpansionResult;
|
||
|
|
use App\Services\Autopodbor\Agent\Study\PhoneReverse;
|
||
|
|
|
||
|
|
function fakeReverse(PhoneExpansionResult $r): PhoneReverse
|
||
|
|
{
|
||
|
|
return new class($r) implements PhoneReverse
|
||
|
|
{
|
||
|
|
public function __construct(private PhoneExpansionResult $r) {}
|
||
|
|
|
||
|
|
public function expand(string $gisSlug, array $seedPhones, array $seedDomains, string $yandexSlug = ''): PhoneExpansionResult
|
||
|
|
{
|
||
|
|
return $this->r;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
it('объединяет сайты обоих провайдеров и дедупит по домену', function () {
|
||
|
|
$a = new PhoneExpansionResult(
|
||
|
|
sites: [['domain' => 'zvezda.ru', 'site_url' => 'https://zvezda.ru', 'card_url' => 'g1']],
|
||
|
|
phones: [['digits' => '73912002288', 'url' => 'g1', 'source' => '2ГИС']],
|
||
|
|
);
|
||
|
|
$b = new PhoneExpansionResult(
|
||
|
|
sites: [
|
||
|
|
['domain' => 'zvezda.ru', 'site_url' => 'https://zvezda.ru', 'card_url' => 'y1'],
|
||
|
|
['domain' => 'sm-city.ru', 'site_url' => 'https://sm-city.ru', 'card_url' => 'y2'],
|
||
|
|
],
|
||
|
|
phones: [['digits' => '73912179941', 'url' => 'y2', 'source' => 'Яндекс']],
|
||
|
|
);
|
||
|
|
$comp = new CompositePhoneReverse([fakeReverse($a), fakeReverse($b)]);
|
||
|
|
$res = $comp->expand('krasnoyarsk', ['x'], [], '62/krasnoyarsk');
|
||
|
|
|
||
|
|
$domains = array_column($res->sites, 'domain');
|
||
|
|
expect($domains)->toContain('zvezda.ru')
|
||
|
|
->and($domains)->toContain('sm-city.ru')
|
||
|
|
->and(count(array_filter($domains, fn ($d) => $d === 'zvezda.ru')))->toBe(1);
|
||
|
|
expect(count($res->phones))->toBe(2);
|
||
|
|
});
|