/** * @param string $request * @param array $params * @param bool $force * * @return string */ public function getContent($request, array $params = [], $force = false) { $path = $this->api_prefix . '&request=' . $request . ($params ? '&' . http_build_query($params) : ''); // try get response from cache if ($force || !$this->cache instanceof CacheResponse || !($response = $this->cache->get($path))) { $response = $this->client->get($path)->setHeader('User-Agent', $this->app_code)->send(); if ($response->isError()) { throw new \RuntimeException("Failed execute request '{$request}' to the server '" . $this->getApiHost() . "'"); } $response = gzdecode($response->getBody(true)); $response = $this->response_repair->repair($response); // repair // cache response if ($this->cache instanceof CacheResponse) { $this->cache->set($request, $path, $response); } } return $response; }
/** * @dataProvider getResponses * * @param string $expected * @param string $actual */ public function testRepair($expected, $actual) { $repair = new ResponseRepair(); $this->assertEquals($expected, $repair->repair($actual)); }