/** * @param string $username * @param string $password * @param string $apiClientType * @param string $httpClientType * * @return ApiClientInterface * * @throws RuntimeException */ public function getClient($username, $password, $apiClientType = 'json', $httpClientType = 'guzzle', $gatewayUrl = null) { if (!in_array(strtolower($apiClientType), $this->apiClientTypes)) { throw new RuntimeException('The API client type "' . $apiClientType . '" is not supported.'); } $clientId = sprintf("%s-%s-%s", strtolower($apiClientType), strtolower($httpClientType), crc32($gatewayUrl)); if (!isset(self::$apiClients[$clientId])) { $httpClient = HttpClientFactory::getInstance()->getClient($username, $password, $httpClientType, $gatewayUrl); $apiClientClass = 'Grow\\Client\\ApiClient\\' . ucfirst(strtolower($apiClientType)) . 'ApiClient'; self::$apiClients[$clientId] = new $apiClientClass($httpClient); } return self::$apiClients[$clientId]; }
/** * @dataProvider httpClientOptionsProvider */ public function testApiClientFactory($httpClientType, $httpClientClassName) { $httpClient = HttpClientFactory::getInstance()->getClient($this->username, $this->password, $httpClientType); $this->assertInstanceOf('Grow\\Client\\HttpClient\\HttpClientInterface', $httpClient); $this->assertInstanceOf($httpClientClassName, $httpClient); }