/** * @param array $data * @param string $expected_class * @dataProvider createConcreteProvider */ public function testCreateConcrete($data, $expected_class) { $response = new Response(); $response->setBody(json_encode(array('error' => $data))); $response->setStatusCode(400); $e = RequestException::create($response); $fqn = '\\FacebookAds\\Http\\Exception\\' . $expected_class; $this->assertTrue(is_a($e, $fqn)); }
/** * @param array $data * @param string $expected_class * @dataProvider createConcreteProvider */ public function testCreateConcrete($data, $expected_class) { $e = RequestException::create(array('error' => $data), 400); $fqn = '\\FacebookAds\\Http\\Exception\\' . $expected_class; $this->assertTrue(is_a($e, $fqn)); }
/** * @param RequestInterface $request * @return ResponseInterface * @throws RequestException */ public function sendRequest(RequestInterface $request) { $response = $this->getAdapter()->sendRequest($request); $response->setRequest($request); $response_content = $response->getContent(); if ($response_content === null) { throw new EmptyResponseException($response->getStatusCode()); } if (is_array($response_content) && array_key_exists('error', $response_content)) { throw RequestException::create($response->getContent(), $response->getStatusCode()); } return $response; }