TestHttpClientWrapper.php in Salesforce Suite 8.4
File
src/Tests/TestHttpClientWrapper.php
View source
<?php
namespace Drupal\salesforce\Tests;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use OAuth\Common\Http\Client\ClientInterface;
use OAuth\Common\Http\Uri\UriInterface;
class TestHttpClientWrapper implements ClientInterface {
protected $httpClient;
public function __construct(GuzzleClientInterface $httpClient) {
$this->httpClient = $httpClient;
}
public function retrieveResponse(UriInterface $endpoint, $requestBody, array $extraHeaders = [], $method = 'POST') {
$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 ?: '';
}
}