Http::response([ 'status_code' => 200, 'response_body_base64' => base64_encode('привет'), ]), ]); $client = new XfetchClient('test-key'); expect($client->html('https://2gis.ru/x'))->toBe('привет'); }); it('без ключа не ходит в сеть и возвращает пусто', function () { Http::fake(); $client = new XfetchClient(null); expect($client->html('https://2gis.ru/x'))->toBe(''); Http::assertNothingSent(); }); it('повторяет запрос при флаки-пустом рендере 2ГИС и берёт удачный', function () { Http::fake(['xf4.ru/*' => Http::sequence() ->push(['response_body_base64' => ''], 200) // 1-й рендер пустой (флак) ->push(['response_body_base64' => base64_encode('x')], 200), // 2-й удачный ]); $client = new XfetchClient('k', retries: 3); expect($client->html('https://2gis.ru/x'))->toContain('73912920000'); }); it('после исчерпания ретраев возвращает пусто', function () { Http::fake(['xf4.ru/*' => Http::response(['response_body_base64' => ''], 200)]); $client = new XfetchClient('k', retries: 2); expect($client->html('https://2gis.ru/x'))->toBe(''); Http::assertSentCount(2); }); it('шлёт url, api_key и render:true на endpoint xfetch', function () { Http::fake(['xf4.ru/*' => Http::response(['response_body_base64' => base64_encode('ok')])]); (new XfetchClient('k123'))->html('https://2gis.ru/y'); Http::assertSent(fn ($r) => $r->url() === 'https://xf4.ru/fetch' && $r['url'] === 'https://2gis.ru/y' && $r['api_key'] === 'k123' && $r['render'] === true); });