private function prepareFixtureFile($methodName) { $tape = $this->createTape($methodName); $httpAdapter = HttpAdapterFactory::guess(); $request = $httpAdapter->getConfiguration()->getMessageFactory()->createRequest('http://httpstat.us/200'); $response = $httpAdapter->sendRequest($request); $exception = new HttpAdapterException(); $exception->setRequest($httpAdapter->getConfiguration()->getMessageFactory()->createInternalRequest('http://httpstat.us/200')); $exception->setResponse($response); $track = new Track($request); $track->setResponse($response); $track->setException($exception); $tape->writeTrack($track); $tape->store(); }
/** * @param InternalRequestInterface $request * @param ResponseInterface $response * * @return HttpAdapterException */ protected function createException(InternalRequestInterface $request = null, ResponseInterface $response = null) { $request = $request ?: $this->createInternalRequest(); $response = $response ?: $this->createResponse(); $e = new HttpAdapterException(); $e->setRequest($request); $e->setResponse($response); return $e; }
/** * @param Ivory\HttpAdapter\HttpAdapterInterface $adapter */ function it_throws_an_exception_when_the_rate_limit_is_exceeded($adapter) { $stream = new StringStream('"Rate limit exceeded. Only one Yo all once per minute."'); $response = new Response(400, '', MessageInterface::PROTOCOL_VERSION_1_1, array(), $stream, array()); $exception = new HttpAdapterException('An error occurred when fetching the URL "https://api.justyo.co/yoall" with the adapter "curl" ("Status code: 400").'); $exception->setResponse($response); $adapter->send(sprintf('%s/yoall/', Yo::ENDPOINT), InternalRequestInterface::METHOD_POST, array(), array('api_token' => self::API_KEY))->willThrow($exception); $this->shouldThrow(new \RuntimeException('[Yo] something went wrong `An error occurred when fetching the URL "https://api.justyo.co/yoall" with the adapter "curl" ("Status code: 400").` the response body was `"Rate limit exceeded. Only one Yo all once per minute."` !'))->duringAll(); }
/** * Gets an HttpAdapterException from an array. * * @param array $data * * @return HttpAdapterException */ public function arrayToException(array $data) { $exception = new HttpAdapterException($data['message'], $data['code']); if (isset($data['request'])) { $exception->setRequest($this->arrayToInternalRequest($data['request'])); } if (isset($data['response'])) { $exception->setResponse($this->arrayToResponse($data['response'])); } return $exception; }