You are here

protected function ResourceTestBase::request in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::request()
  2. 9 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::request()

Performs a HTTP request. Wraps the Guzzle HTTP client.

Why wrap the Guzzle HTTP client? Because we want to keep the actual test code as simple as possible, and hence not require them to specify the 'http_errors = FALSE' request option, nor do we want them to have to convert Drupal Url objects to strings.

We also don't want to follow redirects automatically, to ensure these tests are able to detect when redirects are added or removed.

Parameters

string $method: HTTP method.

\Drupal\Core\Url $url: URL to request.

array $request_options: Request options to apply.

Return value

\Psr\Http\Message\ResponseInterface

See also

\GuzzleHttp\ClientInterface::request()

9 calls to ResourceTestBase::request()
EntityResourceTestBase::assertNormalizationEdgeCases in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Asserts normalization-specific edge cases.
EntityResourceTestBase::assertResourceNotAvailable in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Asserts that a resource is unavailable: 404, 406 if it has canonical route.
EntityResourceTestBase::testDelete in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a DELETE request for an entity, plus edge cases to ensure good DX.
EntityResourceTestBase::testGet in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a GET request for an entity, plus edge cases to ensure good DX.
EntityResourceTestBase::testPatch in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a PATCH request for an entity, plus edge cases to ensure good DX.

... See full list

1 method overrides ResourceTestBase::request()
LayoutRestTestBase::request in core/modules/layout_builder/tests/src/Functional/Rest/LayoutRestTestBase.php
Performs a HTTP request. Wraps the Guzzle HTTP client.

File

core/modules/rest/tests/src/Functional/ResourceTestBase.php, line 348

Class

ResourceTestBase
Subclass this for every REST resource, every format and every auth provider.

Namespace

Drupal\Tests\rest\Functional

Code

protected function request($method, Url $url, array $request_options) {
  $request_options[RequestOptions::HTTP_ERRORS] = FALSE;
  $request_options[RequestOptions::ALLOW_REDIRECTS] = FALSE;
  $request_options = $this
    ->decorateWithXdebugCookie($request_options);
  $client = $this
    ->getHttpClient();
  return $client
    ->request($method, $url
    ->setAbsolute(TRUE)
    ->toString(), $request_options);
}