/** * Internal logged wrapper for HTTP GET request * * @param string $url URL for GET request * * @return type */ protected function _get($url) { $start = microtime(true); try { $result = $this->client()->get($url); } catch (Exception $e) { $result = new Response(['HTTP/1.1 ' . $e->getCode()], $e->getMessage()); } $timeTook = microtime(true) - $start; if (!$result->isOk()) { $this->_httpErrors[] = $result->statusCode() . ' - ' . $result->body(); } if ($this->_connection->logQueries() && $this->_connection->logger()) { $log = new LoggedQuery(); $log->query = $url; $log->took = round($timeTook * 1000); if ($result->isOk()) { $log->numRows = strlen($result->body()); } else { $log->error = new Exception('HTTP Error ' . $result->statusCode() . "\n" . $result->body()); } $this->_connection->logger()->log($log); } return $result; }
/** * Test isOk() * * @return void */ public function testIsOk() { $headers = ['HTTP/1.1 200 OK', 'Content-Type: text/html']; $response = new Response($headers, 'ok'); $this->assertTrue($response->isOk()); $headers = ['HTTP/1.1 201 Created', 'Content-Type: text/html']; $response = new Response($headers, 'ok'); $this->assertTrue($response->isOk()); $headers = ['HTTP/1.1 202 Accepted', 'Content-Type: text/html']; $response = new Response($headers, 'ok'); $this->assertTrue($response->isOk()); $headers = ['HTTP/1.1 301 Moved Permanently', 'Content-Type: text/html']; $response = new Response($headers, ''); $this->assertFalse($response->isOk()); $headers = ['HTTP/1.0 404 Not Found', 'Content-Type: text/html']; $response = new Response($headers, ''); $this->assertFalse($response->isOk()); }