/**
  * Create service with name
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @param $name
  * @param $requestedName
  * @return mixed
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     $allConfigs = $this->getConfig($serviceLocator);
     $config = $allConfigs[$requestedName];
     $httpClient = new HttpClient();
     if (isset($config['http_client_options'])) {
         $httpClient->setOptions($config['http_client_options']);
     }
     $client = new Client($httpClient, $config['base_uri']);
     if (isset($config['default_headers'])) {
         $client->setDefaultHeaders($config['default_headers']);
     }
     if (isset($config['throw_exceptions'])) {
         $client->setThrowExceptions($config['throw_exceptions']);
     }
     return $client;
 }
Example #2
0
 public function testCallHttpPost()
 {
     $data = ['testName' => 'testValue'];
     $request = new Request();
     $request->setUri('http://test.dev/testapi');
     $request->setMethod(Request::METHOD_POST);
     $request->setContent(json_encode($data));
     $request->getHeaders()->addHeaders(array('Accept' => 'application/json'));
     $response = new Response();
     $responseData = ['id' => 17, 'testName' => 'testValue'];
     $response->setContent(json_encode($responseData));
     $httpClient = $this->getMock('Zend\\Http\\Client', array('send'));
     $httpClient->expects($this->once())->method('send')->with($this->equalTo($request))->will($this->returnValue($response));
     $client = new Client($httpClient, 'http://test.dev/', ['Accept' => 'application/json']);
     $this->assertEquals((object) $responseData, $client->call('/testapi', Request::METHOD_POST, $data));
 }