public function testPayload()
 {
     $payload = $this->createPayload();
     $this->assertInternalType('string', $payload->getMethod());
     $this->assertTrue(class_exists($payload->getResponseClass()));
     $this->assertTrue(class_exists($payload->getHandlerClass()));
     $handler = PayloadHandlerFactory::getHandler($payload);
     $actualData = $handler->get();
     $expectedData = $this->getExpectedPayloadData($payload);
     $this->assertEquals($expectedData, $actualData);
 }
Example #2
0
 /**
  * @param string      $method
  * @param array       $data
  * @param string|null $apiKey
  *
  * @throws EuropeanaException
  *
  * @return array
  */
 private function doSend($payload, $apiKey = null)
 {
     try {
         $method = $payload->getMethod();
         $handler = PayloadHandlerFactory::getHandler($payload);
         $data = $handler->get();
         $data[] = array('wskey', $apiKey ? $apiKey : $this->apiKey);
         $request = $this->createRequest($method, $data);
         /** @var ResponseInterface $response */
         $response = $this->client->send($request);
     } catch (\Exception $e) {
         throw new EuropeanaException('Failed to send data to the Europeana API', null, $e);
     }
     try {
         $data = $response->getBody();
         $responseData = json_decode($data, true, 512, JSON_BIGINT_AS_STRING);
         if (!is_array($responseData)) {
             throw new \Exception(sprintf('Expected JSON-decoded response data to be of type "array", got "%s"', gettype($responseData)));
         }
         return $responseData;
     } catch (\Exception $e) {
         throw new EuropeanaException('Failed to process response from the Europeana API', null, $e);
     }
 }