class TestHttpClientWrapper in Salesforce Suite 8.4
Same name and namespace in other branches
- 5.0.x src/Tests/TestHttpClientWrapper.php \Drupal\salesforce\Tests\TestHttpClientWrapper
Wraps Guzzle HTTP client for an OAuth ClientInterface.
Hierarchy
- class \Drupal\salesforce\Tests\TestHttpClientWrapper implements \OAuth\Common\Http\Client\ClientInterface
Expanded class hierarchy of TestHttpClientWrapper
1 file declares its use of TestHttpClientWrapper
- SalesforceTestRestClientServiceProvider.php in tests/
modules/ salesforce_test_rest_client/ src/ SalesforceTestRestClientServiceProvider.php
File
- src/
Tests/ TestHttpClientWrapper.php, line 12
Namespace
Drupal\salesforce\TestsView source
class TestHttpClientWrapper implements ClientInterface {
/**
* Guzzle HTTP Client service.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* HttpClientWrapper constructor.
*
* @param \GuzzleHttp\ClientInterface $httpClient
* Guzzle HTTP client service, from core http_client.
*/
public function __construct(GuzzleClientInterface $httpClient) {
$this->httpClient = $httpClient;
}
/**
* {@inheritdoc}
*/
public function retrieveResponse(UriInterface $endpoint, $requestBody, array $extraHeaders = [], $method = 'POST') {
// This method is only used to Salesforce OAuth. Based on the given args,
// return a hard-coded version of the expected response.
$dir = drupal_get_path('module', 'salesforce') . '/src/Tests/';
if ($endpoint
->getPath() == '/services/oauth2/token') {
switch ($requestBody['grant_type']) {
case 'authorization_code':
$content = file_get_contents($dir . '/oauthResponse.json');
case 'urn:ietf:params:oauth:grant-type:jwt-bearer':
$content = file_get_contents($dir . '/jwtAuthResponse.json');
}
}
elseif ($endpoint
->getPath() == '/id/XXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXX') {
$content = file_get_contents($dir . '/identityResponse.json');
}
return $content ?: '';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestHttpClientWrapper:: |
protected | property | Guzzle HTTP Client service. | |
TestHttpClientWrapper:: |
public | function | ||
TestHttpClientWrapper:: |
public | function | HttpClientWrapper constructor. |