You are here

class TestHttpClientWrapper in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 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\Tests
View 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

Namesort descending Modifiers Type Description Overrides
TestHttpClientWrapper::$httpClient protected property Guzzle HTTP Client service.
TestHttpClientWrapper::retrieveResponse public function
TestHttpClientWrapper::__construct public function HttpClientWrapper constructor.