toBeInstanceOf(PageFetcher::class) ->and(client())->toBeInstanceOf(BatchPageFetcher::class); }); it('html: POST на endpoint, тип initialState для 2ГИС, отдаёт data', function () { Http::fake([EP => Http::response(['data' => '{"state":1}'], 200)]); $out = client()->html('https://2gis.ru/krasnoyarsk/search/ломбард'); expect($out)->toBe('{"state":1}'); Http::assertSent(fn ($r) => $r->url() === EP && $r['url'] === 'https://2gis.ru/krasnoyarsk/search/ломбард' && $r['type'] === 'initialState' && $r->hasHeader('X-Render-Key', 'secret')); }); it('html: тип html для Яндекса и прочего', function () { Http::fake([EP => Http::response(['data' => 'ya'], 200)]); expect(client()->html('https://yandex.ru/maps/org/1'))->toBe('ya'); Http::assertSent(fn ($r) => $r['type'] === 'html'); }); it('без ключа или адреса → пусто, запрос не шлётся (деградация)', function () { Http::fake([EP => Http::response(['data' => 'x'], 200)]); expect(client(['key' => ''])->html('https://2gis.ru/x'))->toBe('') ->and(client(['endpoint' => ''])->html('https://2gis.ru/x'))->toBe(''); Http::assertNothingSent(); }); it('htmlBatch: карта url => data', function () { Http::fake([EP => function ($request) { return Http::response(['data' => 'R:'.$request['url']], 200); }]); $urls = ['https://2gis.ru/a', 'https://2gis.ru/b']; expect(client()->htmlBatch($urls))->toBe([ 'https://2gis.ru/a' => 'R:https://2gis.ru/a', 'https://2gis.ru/b' => 'R:https://2gis.ru/b', ]); }); it('htmlBatch: пустой ключ → все пусто, без запросов', function () { Http::fake([EP => Http::response(['data' => 'x'], 200)]); expect(client(['key' => ''])->htmlBatch(['https://2gis.ru/a']))->toBe(['https://2gis.ru/a' => '']); Http::assertNothingSent(); }); it('html: неуспешный ответ → пусто', function () { Http::fake([EP => Http::response('', 500)]); expect(client()->html('https://2gis.ru/x'))->toBe(''); });