You are here

trait RequestHelperTrait in Simple OAuth (OAuth2) & OpenID Connect 8.2

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/RequestHelperTrait.php \Drupal\Tests\simple_oauth\Functional\RequestHelperTrait
  2. 8.3 tests/src/Functional/RequestHelperTrait.php \Drupal\Tests\simple_oauth\Functional\RequestHelperTrait
  3. 5.x tests/src/Functional/RequestHelperTrait.php \Drupal\Tests\simple_oauth\Functional\RequestHelperTrait

Hierarchy

1 file declares its use of RequestHelperTrait
RolesNegotiationFunctionalTest.php in simple_oauth_extras/tests/src/Functional/RolesNegotiationFunctionalTest.php

File

tests/src/Functional/RequestHelperTrait.php, line 10

Namespace

Drupal\Tests\simple_oauth\Functional
View source
trait RequestHelperTrait {

  /**
   * Performs a HTTP request. Wraps the Guzzle HTTP client.
   *
   * Why wrap the Guzzle HTTP client? Because any error response is returned via
   * an exception, which would make the tests unnecessarily complex to read.
   *
   * @param string $method
   *   HTTP method.
   * @param \Drupal\Core\Url $url
   *   URL to request.
   * @param array $request_options
   *   Request options to apply.
   *
   * @return \Psr\Http\Message\ResponseInterface
   *   The response
   *
   * @see \GuzzleHttp\ClientInterface::request()
   */
  protected function request($method, Url $url, array $request_options) {
    try {
      $response = $this->httpClient
        ->request($method, $url
        ->toString(), $request_options);
    } catch (ClientException $e) {
      $response = $e
        ->getResponse();
    } catch (ServerException $e) {
      $response = $e
        ->getResponse();
    } catch (RequestException $e) {
      $response = $e
        ->getResponse();
    }
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RequestHelperTrait::request protected function Performs a HTTP request. Wraps the Guzzle HTTP client.