/** * Create service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return HttpApi */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $config = $this->getConfig($serviceLocator)[$requestedName]; $httpClient = isset($config['http_client']) && $serviceLocator->has($config['http_client']) ? $serviceLocator->get($config['http_client']) : null; $baseRequest = isset($config['base_request']) && $serviceLocator->has($config['base_request']) ? $serviceLocator->get($config['base_request']) : null; $api = new HttpApi($httpClient, $baseRequest); // Array of int code valid if (isset($config['valid_status_code']) && is_array($config['valid_status_code'])) { $api->setValidStatusCodes($config['valid_status_code']); } // string json/xml if (isset($config['request_format'])) { $api->setRequestFormat($config['request_format']); } // Profiler if (isset($config['profiler']) && $serviceLocator->has($config['profiler'])) { $api->setProfiler($serviceLocator->get($config['profiler'])); } return $api; }
public function testPrepareRequestShouldThrowExceptionOnInvalidFormat() { $this->httpApi->setRequestFormat('invalid format'); $this->setExpectedException('\\Matryoshka\\Service\\Api\\Exception\\InvalidFormatException'); $this->httpApi->prepareRequest('post', null, ['foo' => 'baz']); }