/** * Makes an API call, handles errors and returns the response. * * @return array An associative array of processed data. */ public function getData() { $data = array(); try { $apiKey = \Config::get('tdteuropeana.apiKey'); $client = new Client(); $apiClient = new ApiClient($apiKey, $client); $payload = $this->getPayload(); $payloadResponse = $apiClient->send($payload); $data = $this->parseResponse($payloadResponse); } catch (EuropeanaException $e) { // throw an error } return $data; }
public function testSendWithoutKey() { /** @var PayloadInterface|\PHPUnit_Framework_MockObject_MockObject $mockPayload */ $mockPayload = $this->getMock('Colada\\Europeana\\Payload\\PayloadInterface'); $apiClient = new ApiClient(); try { $apiClient->send($mockPayload); } catch (EuropeanaException $e) { $previous = $e->getPrevious(); $this->assertInstanceOf('\\InvalidArgumentException', $previous); $this->assertEquals('You must supply an API key to send a payload, since you did not provide one during construction', $previous->getMessage()); return; } $this->markTestIncomplete('This test should have thrown an exception'); }