/**
  * Create service with name
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @param $name
  * @param $requestedName
  * @return mixed
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     $config = $this->getConfig($serviceLocator)[$requestedName];
     $resourceName = $config['resource_name'];
     /** @var $httpClient Client */
     $httpClient = isset($config['http_client']) && $serviceLocator->has($config['http_client']) ? $serviceLocator->get($config['http_client']) : null;
     /** @var $baseRequest Request */
     $baseRequest = isset($config['base_request']) && $serviceLocator->has($config['base_request']) ? $serviceLocator->get($config['base_request']) : null;
     $restClient = new RestClient($resourceName, $httpClient, $baseRequest);
     if (isset($config['uri_resource_strategy']) && $serviceLocator->has($config['uri_resource_strategy'])) {
         $restClient->setUriResourceStrategy($serviceLocator->get($config['uri_resource_strategy']));
     }
     // Array of int code valid
     if (isset($config['valid_status_code']) && is_array($config['valid_status_code'])) {
         $restClient->setValidStatusCodes($config['valid_status_code']);
     }
     // string json/xml
     if (isset($config['request_format'])) {
         $restClient->setRequestFormat($config['request_format']);
     }
     // Profiler
     if (isset($config['profiler']) && $serviceLocator->has($config['profiler'])) {
         $restClient->setProfiler($serviceLocator->get($config['profiler']));
     }
     return $restClient;
 }
 public function setUp()
 {
     /** @var $httpClient Request */
     $httpClient = $this->getMockBuilder('Zend\\Http\\Client')->disableOriginalConstructor()->setMethods(['dispatch', 'getResponse'])->getMock();
     $client = new RestClient('test', $httpClient);
     /** @var $profiler ProfilerInterface */
     $profiler = $this->getMock('Matryoshka\\Service\\Api\\Profiler\\ProfilerInterface');
     $client->setRequestFormat('application/json');
     $client->setProfiler($profiler);
     $this->restClient = $client;
     $modelMock = $this->getMockBuilder('\\Matryoshka\\Model\\AbstractModel')->disableOriginalConstructor()->setMethods(['find', 'getDataGateway'])->getMockForAbstractClass();
     $this->modelMock = $modelMock;
     $criteria = new FindAllCriteria();
     $this->criteria = $criteria;
     /** @var $modelMock ModelStubInterface */
     $this->paginatorAdapter = new RestPaginatorAdapter($modelMock, $criteria);
 }
 public function testPrepareRequestShouldThrowExceptionOnInvalidFormat()
 {
     $this->restClient->setRequestFormat('invalid format');
     $this->setExpectedException('\\Matryoshka\\Service\\Api\\Exception\\InvalidFormatException');
     $this->restClient->prepareRequest('post', null, ['foo' => 'baz']);
 }