/**
  * @param $method
  * @param array $params
  * @param $contentResponse
  * @param $responseContentType
  * @param $typeResponse
  * @dataProvider providerServiceResponse
  */
 public function testHttpMethod($method, array $params, $contentResponse, $responseContentType, $typeResponse)
 {
     $httpClient = $this->getMockBuilder('Zend\\Http\\Client')->disableOriginalConstructor()->setMethods(['dispatch', 'getResponse'])->getMock();
     $response = new Response();
     $response->setContent($contentResponse);
     $response->getHeaders()->addHeaderLine('Content-Type', $responseContentType);
     $httpClient->expects($this->any())->method('dispatch')->will($this->returnValue($response));
     $httpClient->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     /** @var $httpClient \Zend\Http\Client */
     $client = new RestClient('test', $httpClient);
     $profiler = $this->getMock('Matryoshka\\Service\\Api\\Profiler\\ProfilerInterface');
     $client->setRequestFormat($typeResponse);
     /** @var $profiler \Matryoshka\Service\Api\Profiler\ProfilerInterface */
     $client->setProfiler($profiler);
     call_user_func_array([$client, $method], $params);
     $this->assertInternalType('array', call_user_func_array([$client, $method], $params));
     $this->assertInstanceof('\\Zend\\Http\\Request', $client->getLastRequest());
     $this->assertSame($response, $client->getLastResponse());
     $this->assertSame($client->getResponseDecoder()->getLastPayload(), $client->getLastResponseData());
     // Test query params
     if (in_array($method, ['delete', 'get', 'head', 'post']) && isset($params[1]) && ($query = $params[1]) || in_array($method, ['options']) && isset($params[0]) && ($query = $params[0]) || in_array($method, ['patch', 'put']) && isset($params[2]) && ($query = $params[2])) {
         $request = $client->getLastRequest();
         foreach ($query as $key => $value) {
             $this->assertEquals($value, $request->getQuery($key));
         }
     }
 }
 /**
  * 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);
 }